Merge branch 'gnu'

This commit is contained in:
Joel Dice
2009-08-03 09:01:16 -06:00
69 changed files with 3828 additions and 1060 deletions

View File

@ -0,0 +1,22 @@
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.lang;
import java.io.IOException;
public interface Appendable {
public Appendable append(char c) throws IOException;
public Appendable append(CharSequence sequence) throws IOException;
public Appendable append(CharSequence sequence, int start, int end)
throws IOException;
}

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
@ -10,7 +10,7 @@
package java.lang;
public class ArrayIndexOutOfBoundsException extends RuntimeException {
public class ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException {
public ArrayIndexOutOfBoundsException(String message, Throwable cause) {
super(message, cause);
}

View File

@ -187,4 +187,40 @@ public final class Character implements Comparable<Character> {
return isHighSurrogate(high) && isLowSurrogate(low);
}
public static int codePointAt(CharSequence sequence, int offset) {
int length = sequence.length();
if (offset < 0 || offset >= length) {
throw new IndexOutOfBoundsException();
}
char high = sequence.charAt(offset);
if (! isHighSurrogate(high) || offset >= length) {
return high;
}
char low = sequence.charAt(offset + 1);
if (! isLowSurrogate(low)) {
return high;
}
return toCodePoint(high, low);
}
public static int codePointCount(CharSequence sequence, int start, int end) {
int length = sequence.length();
if (start < 0 || start > end || end >= length) {
throw new IndexOutOfBoundsException();
}
int count = 0;
for (int i = start; i < end; ++i) {
if (isHighSurrogate(sequence.charAt(i))
&& (i + 1) < end
&& isLowSurrogate(sequence.charAt(i + 1)))
{
++ i;
}
++ count;
}
return count;
}
}

View File

@ -14,12 +14,19 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.GenericDeclaration;
import java.lang.annotation.Annotation;
import java.io.InputStream;
import java.io.IOException;
import java.net.URL;
import java.security.ProtectionDomain;
import java.security.Permissions;
import java.security.AllPermission;
public final class Class <T> {
public final class Class <T> implements Type, GenericDeclaration {
private static final int PrimitiveFlag = 1 << 4;
private short flags;
@ -84,6 +91,9 @@ public final class Class <T> {
ClassLoader loader)
throws ClassNotFoundException
{
if (loader == null) {
loader = Class.class.loader;
}
Class c = loader.loadClass(name);
if (initialize) {
c.initialize();
@ -168,6 +178,8 @@ public final class Class <T> {
private Method findMethod(String name, Class[] parameterTypes) {
if (methodTable != null) {
if (parameterTypes == null)
parameterTypes = new Class[0];
for (int i = 0; i < methodTable.length; ++i) {
if (methodTable[i].getName().equals(name)
&& match(parameterTypes, methodTable[i].getParameterTypes()))
@ -434,8 +446,63 @@ public final class Class <T> {
return null;
}
}
public boolean desiredAssertionStatus() {
return false;
}
public T cast(Object o) {
return (T) o;
}
public Object[] getSigners() {
throw new UnsupportedOperationException();
}
public Annotation[] getDeclaredAnnotations() {
throw new UnsupportedOperationException();
}
public boolean isEnum() {
throw new UnsupportedOperationException();
}
public TypeVariable<Class<T>>[] getTypeParameters() {
throw new UnsupportedOperationException();
}
public String getSimpleName() {
throw new UnsupportedOperationException();
}
public Method getEnclosingMethod() {
throw new UnsupportedOperationException();
}
public Constructor getEnclosingConstructor() {
throw new UnsupportedOperationException();
}
public Class getEnclosingClass() {
throw new UnsupportedOperationException();
}
public Class[] getDeclaredClasses() {
throw new UnsupportedOperationException();
}
public <A extends Annotation> A getAnnotation(Class<A> c) {
throw new UnsupportedOperationException();
}
public ProtectionDomain getProtectionDomain() {
Permissions p = new Permissions();
p.add(new AllPermission());
return new ProtectionDomain(null, p);
}
// for GNU Classpath compatibility:
void setSigners(Object[] signers) {
throw new UnsupportedOperationException();
}
}

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
@ -11,8 +11,11 @@
package java.lang;
public class ClassNotFoundException extends Exception {
private final Throwable cause2;
public ClassNotFoundException(String message, Throwable cause) {
super(message, cause);
cause2 = cause;
}
public ClassNotFoundException(String message) {

View File

@ -53,4 +53,12 @@ public abstract class Enum<E extends Enum<E>> implements Comparable<E> {
public String toString() {
return name;
}
public Class<E> getDeclaringClass() {
Class c = getClass();
while (c.getSuperclass() != Enum.class) {
c = c.getSuperclass();
}
return c;
}
}

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
@ -11,11 +11,14 @@
package java.lang;
public class ExceptionInInitializerError extends Error {
private final Throwable cause2;
public ExceptionInInitializerError(String message) {
super(message);
cause2 = null;
}
public ExceptionInInitializerError() {
super();
this(null);
}
}

View File

@ -25,7 +25,7 @@ public class Object {
return this == o;
}
protected void finalize() { }
protected void finalize() throws Throwable { }
public native final Class<? extends Object> getClass();
@ -41,5 +41,14 @@ public class Object {
wait(0);
}
public native final void wait(long timeout) throws InterruptedException;
public native final void wait(long milliseconds) throws InterruptedException;
public final void wait(long milliseconds, int nanoseconds)
throws InterruptedException
{
if (nanoseconds != 0) {
++ milliseconds;
}
wait(milliseconds);
}
}

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
@ -10,9 +10,9 @@
package java.lang;
public class StackOverflowError extends Error {
public class StackOverflowError extends VirtualMachineError {
public StackOverflowError(String message) {
super(message, null);
super(message);
}
public StackOverflowError() {

View File

@ -18,8 +18,8 @@ public class StackTraceElement {
private String file;
private int line;
private StackTraceElement(String class_, String method, String file,
int line)
public StackTraceElement(String class_, String method, String file,
int line)
{
this.class_ = class_;
this.method = method;
@ -56,7 +56,7 @@ public class StackTraceElement {
}
public String getClassName() {
return class_;
return class_.replace('/', '.');
}
public String getMethodName() {

View File

@ -12,14 +12,30 @@ package java.lang;
import java.io.UnsupportedEncodingException;
import java.util.regex.Pattern;
import java.util.Comparator;
import java.util.Locale;
import java.io.ByteArrayOutputStream;
import java.io.Serializable;
public final class String
implements Comparable<String>, CharSequence, Serializable
{
public static Comparator<String> CASE_INSENSITIVE_ORDER
= new Comparator<String>() {
public int compare(String a, String b) {
return a.compareToIgnoreCase(b);
}
};
public final class String implements Comparable<String>, CharSequence {
private final Object data;
private final int offset;
private final int length;
private int hashCode;
public String() {
this(new char[0], 0, 0);
}
public String(char[] data, int offset, int length, boolean copy) {
this((Object) data, offset, length, copy);
}
@ -32,9 +48,11 @@ public final class String implements Comparable<String>, CharSequence {
this(data, 0, data.length);
}
public String(byte bytes[], int offset, int length, String charsetName) throws UnsupportedEncodingException {
public String(byte bytes[], int offset, int length, String charsetName)
throws UnsupportedEncodingException
{
this(bytes, offset, length);
if (!charsetName.equals("UTF-8")) {
if (! charsetName.equalsIgnoreCase("UTF-8")) {
throw new UnsupportedEncodingException(charsetName);
}
}
@ -57,12 +75,29 @@ public final class String implements Comparable<String>, CharSequence {
public String(byte[] data, String charset)
throws UnsupportedEncodingException
{
this(data);
if (! charset.equals("UTF-8")) {
throw new UnsupportedEncodingException(charset);
}
{
this(data);
if (! charset.equals("UTF-8")) {
throw new UnsupportedEncodingException(charset);
}
}
public String(byte bytes[], int highByte, int offset, int length) {
if (offset < 0 || offset + length > bytes.length) {
throw new IndexOutOfBoundsException
(offset + " < 0 or " + offset + " + " + length + " > " + bytes.length);
}
char[] c = new char[length];
int mask = highByte << 8;
for (int i = 0; i < length; ++i) {
c[i] = (char) ((bytes[offset + i] & 0xFF) | mask);
}
this.data = c;
this.offset = 0;
this.length = length;
}
private String(Object data, int offset, int length, boolean copy) {
int l;
@ -200,7 +235,7 @@ public final class String implements Comparable<String>, CharSequence {
}
public boolean equalsIgnoreCase(String s) {
return this == s || compareToIgnoreCase(s) == 0;
return this == s || (s != null && compareToIgnoreCase(s) == 0);
}
public int compareTo(String s) {
@ -381,7 +416,7 @@ public final class String implements Comparable<String>, CharSequence {
}
} else {
throw new IndexOutOfBoundsException
(start + " not in (0, " + end + ") or " + end + " > " + length);
(start + " not in [0, " + end + ") or " + end + " > " + length);
}
}
@ -534,6 +569,10 @@ public final class String implements Comparable<String>, CharSequence {
return Pattern.matches(regex, this);
}
public String replaceAll(String regex, String replacement) {
return Pattern.compile(regex).matcher(this).replaceAll(replacement);
}
public native String intern();
public static String valueOf(Object s) {
@ -557,7 +596,9 @@ public final class String implements Comparable<String>, CharSequence {
}
public static String valueOf(int v) {
return Integer.toString(v);
// use Integer.toString(int, int), because GNU Classpath's
// Integer.toString(int) just calls String.valueOf(int):
return Integer.toString(v, 10);
}
public static String valueOf(long v) {
@ -572,6 +613,14 @@ public final class String implements Comparable<String>, CharSequence {
return Double.toString(v);
}
public static String valueOf(char[] data, int offset, int length) {
return new String(data, offset, length);
}
public static String valueOf(char[] data) {
return valueOf(data, 0, data.length);
}
public int lastIndexOf(int ch, int lastIndex) {
for (int i = lastIndex ; i >= 0; --i) {
if (charAt(i) == ch) {
@ -581,4 +630,63 @@ public final class String implements Comparable<String>, CharSequence {
return -1;
}
public boolean regionMatches(int thisOffset, String match, int matchOffset,
int length)
{
return regionMatches(false, thisOffset, match, matchOffset, length);
}
public boolean regionMatches(boolean ignoreCase, int thisOffset,
String match, int matchOffset, int length)
{
String a = substring(thisOffset, thisOffset + length);
String b = match.substring(matchOffset, matchOffset + length);
if (ignoreCase) {
return a.equalsIgnoreCase(b);
} else {
return a.equals(b);
}
}
public boolean isEmpty() {
return length == 0;
}
public boolean contains(String match) {
return indexOf(match) != -1;
}
public int codePointAt(int offset) {
return Character.codePointAt(this, offset);
}
public int codePointCount(int start, int end) {
return Character.codePointCount(this, start, end);
}
public String replace(CharSequence match, CharSequence replacement) {
throw new UnsupportedOperationException();
}
public String toUpperCase(Locale locale) {
throw new UnsupportedOperationException();
}
public String toLowerCase(Locale locale) {
throw new UnsupportedOperationException();
}
// for GNU Classpath compatibility:
static char[] zeroBasedStringValue(String s) {
if (s.offset == 0) {
if (s.data instanceof char[]) {
char[] data = (char[]) s.data;
if (data.length == s.length) {
return data;
}
}
}
return s.toCharArray();
}
}

View File

@ -10,7 +10,7 @@
package java.lang;
public class StringBuilder implements CharSequence {
public class StringBuilder implements CharSequence, Appendable {
private static final int BufferSize = 32;
private Cell chain;
@ -54,6 +54,14 @@ public class StringBuilder implements CharSequence {
}
}
public StringBuilder append(CharSequence sequence) {
return append(sequence.toString());
}
public Appendable append(CharSequence sequence, int start, int end) {
return append(sequence.subSequence(start, end));
}
public StringBuilder append(char[] b, int offset, int length) {
return append(new String(b, offset, length));
}
@ -150,6 +158,10 @@ public class StringBuilder implements CharSequence {
return this;
}
public StringBuilder insert(int i, CharSequence s) {
return insert(i, s.toString());
}
public StringBuilder insert(int i, char c) {
return insert(i, new String(new char[] { c }, 0, 1, false));
}
@ -332,4 +344,8 @@ public class StringBuilder implements CharSequence {
deleteCharAt(index);
insert(index, ch);
}
public void ensureCapacity(int capacity) {
// ignore
}
}

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
@ -15,14 +15,30 @@ import java.util.WeakHashMap;
public class Thread implements Runnable {
private long peer;
private boolean interrupted;
private boolean daemon;
private byte state;
private byte priority;
private final Runnable task;
private Map<ThreadLocal, Object> locals;
private boolean interrupted;
private Object sleepLock;
private ClassLoader classLoader;
private String name;
private UncaughtExceptionHandler exceptionHandler;
public Thread(Runnable task, String name) {
// package private for GNU Classpath, which inexplicably bypasses
// the accessor methods:
String name;
ThreadGroup group;
private static UncaughtExceptionHandler defaultExceptionHandler;
public static final int MIN_PRIORITY = 1;
public static final int NORM_PRIORITY = 5;
public static final int MAX_PRIORITY = 10;
public Thread(ThreadGroup group, Runnable task, String name, long stackSize)
{
this.group = group;
this.task = task;
this.name = name;
@ -41,8 +57,28 @@ public class Thread implements Runnable {
classLoader = current.classLoader;
}
public Thread(ThreadGroup group, Runnable task, String name) {
this(group, task, name, 0);
}
public Thread(ThreadGroup group, String name) {
this(null, null, name);
}
public Thread(Runnable task, String name) {
this(null, task, name);
}
public Thread(Runnable task) {
this(task, "Thread["+task+"]");
this(null, task, "Thread["+task+"]");
}
public Thread(String name) {
this(null, null, name);
}
public Thread() {
this((Runnable) null);
}
public synchronized void start() {
@ -58,6 +94,28 @@ public class Thread implements Runnable {
private native long doStart();
private static void run(Thread t) throws Throwable {
t.state = (byte) State.RUNNABLE.ordinal();
try {
t.run();
} catch (Throwable e) {
UncaughtExceptionHandler eh = t.exceptionHandler;
UncaughtExceptionHandler deh = defaultExceptionHandler;
if (eh != null) {
eh.uncaughtException(t, e);
} else if (deh != null) {
deh.uncaughtException(t, e);
} else {
throw e;
}
} finally {
synchronized (t) {
t.state = (byte) State.TERMINATED.ordinal();
t.notifyAll();
}
}
}
public void run() {
if (task != null) {
task.run();
@ -101,6 +159,10 @@ public class Thread implements Runnable {
}
}
public static boolean isInterrupted() {
return currentThread().interrupted;
}
public static void sleep(long milliseconds) throws InterruptedException {
Thread t = currentThread();
if (t.sleepLock == null) {
@ -111,6 +173,16 @@ public class Thread implements Runnable {
}
}
public static void sleep(long milliseconds, int nanoseconds)
throws InterruptedException
{
if (nanoseconds > 0) {
++ milliseconds;
}
sleep(milliseconds);
}
public StackTraceElement[] getStackTrace() {
return Throwable.resolveTrace(getStackTrace(peer));
}
@ -124,5 +196,125 @@ public class Thread implements Runnable {
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public UncaughtExceptionHandler getUncaughtExceptionHandler() {
UncaughtExceptionHandler eh = exceptionHandler;
return (eh == null ? group : eh);
}
public static UncaughtExceptionHandler getDefaultUncaughtExceptionHandler() {
return defaultExceptionHandler;
}
public void setUncaughtExceptionHandler(UncaughtExceptionHandler h) {
exceptionHandler = h;
}
public static void setDefaultUncaughtExceptionHandler
(UncaughtExceptionHandler h)
{
defaultExceptionHandler = h;
}
public State getState() {
return State.values()[state];
}
public boolean isAlive() {
switch (getState()) {
case NEW:
case TERMINATED:
return false;
default:
return true;
}
}
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
if (priority < MIN_PRIORITY || priority > MAX_PRIORITY) {
throw new IllegalArgumentException();
}
this.priority = (byte) priority;
}
public boolean isDaemon() {
return daemon;
}
public void setDaemon(boolean v) {
daemon = v;
}
public static native void yield();
public synchronized void join() throws InterruptedException {
while (getState() != State.TERMINATED) {
wait();
}
}
public synchronized void join(long milliseconds) throws InterruptedException
{
long then = System.currentTimeMillis();
long remaining = milliseconds;
while (remaining > 0 && getState() != State.TERMINATED) {
wait(remaining);
remaining = milliseconds - (System.currentTimeMillis() - then);
}
}
public void join(long milliseconds, int nanoseconds)
throws InterruptedException
{
if (nanoseconds > 0) {
++ milliseconds;
}
join(milliseconds);
}
public ThreadGroup getThreadGroup() {
return group;
}
public static native boolean holdsLock(Object o);
public long getId() {
return peer;
}
public void stop() {
throw new UnsupportedOperationException();
}
public void stop(Throwable t) {
throw new UnsupportedOperationException();
}
public void suspend() {
throw new UnsupportedOperationException();
}
public void resume() {
throw new UnsupportedOperationException();
}
public interface UncaughtExceptionHandler {
public void uncaughtException(Thread t, Throwable e);
}
public enum State {
NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, TERMINATED
}
}

View File

@ -0,0 +1,15 @@
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.lang;
public class ThreadDeath extends Error {
public ThreadDeath() { }
}

View File

@ -0,0 +1,35 @@
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.lang;
public class ThreadGroup implements Thread.UncaughtExceptionHandler {
private final ThreadGroup parent;
private final String name;
public ThreadGroup(ThreadGroup parent, String name) {
this.parent = parent;
this.name = name;
}
public void uncaughtException(Thread t, Throwable e) {
if (parent != null) {
parent.uncaughtException(t, e);
} else {
Thread.UncaughtExceptionHandler deh
= Thread.getDefaultUncaughtExceptionHandler();
if (deh != null) {
deh.uncaughtException(t, e);
} else if (! (e instanceof ThreadDeath)) {
e.printStackTrace();
}
}
}
}

View File

@ -13,8 +13,9 @@ package java.lang;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.Serializable;
public class Throwable {
public class Throwable implements Serializable {
private String message;
private Object trace;
private Throwable cause;
@ -109,4 +110,9 @@ public class Throwable {
cause.printStackTrace(sb, nl);
}
}
public Throwable fillInStackTrace() {
trace = trace(0);
return this;
}
}

View File

@ -0,0 +1,21 @@
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.lang;
public class VirtualMachineError extends Error {
public VirtualMachineError(String message) {
super(message);
}
public VirtualMachineError() {
this(null);
}
}

View File

@ -22,6 +22,10 @@ public abstract class Reference<T> {
this.queue = queue;
}
protected Reference(T target) {
this(target, null);
}
public T get() {
return target;
}

View File

@ -10,7 +10,9 @@
package java.lang.reflect;
public class Constructor<T> extends AccessibleObject implements Member {
public class Constructor<T> extends AccessibleObject
implements Member, GenericDeclaration
{
private Method<T> method;
public Constructor(Method<T> method) {
@ -46,6 +48,18 @@ public class Constructor<T> extends AccessibleObject implements Member {
return method.getName();
}
public boolean isSynthetic() {
return method.isSynthetic();
}
public TypeVariable<Constructor<T>>[] getTypeParameters() {
throw new UnsupportedOperationException();
}
public Type[] getGenericParameterTypes() {
return method.getGenericParameterTypes();
}
private static native <T> T make(Class<T> c);
public T newInstance(Object ... arguments)

View File

@ -101,6 +101,38 @@ public class Field<T> extends AccessibleObject {
}
}
public boolean getBoolean(Object instance) throws IllegalAccessException {
return ((Boolean) get(instance)).booleanValue();
}
public byte getByte(Object instance) throws IllegalAccessException {
return ((Byte) get(instance)).byteValue();
}
public short getShort(Object instance) throws IllegalAccessException {
return ((Short) get(instance)).shortValue();
}
public char getChar(Object instance) throws IllegalAccessException {
return ((Character) get(instance)).charValue();
}
public int getInt(Object instance) throws IllegalAccessException {
return ((Integer) get(instance)).intValue();
}
public float getFloat(Object instance) throws IllegalAccessException {
return ((Float) get(instance)).floatValue();
}
public long getLong(Object instance) throws IllegalAccessException {
return ((Long) get(instance)).longValue();
}
public double getDouble(Object instance) throws IllegalAccessException {
return ((Double) get(instance)).doubleValue();
}
public void set(Object instance, Object value)
throws IllegalAccessException
{
@ -162,6 +194,10 @@ public class Field<T> extends AccessibleObject {
}
}
public boolean isEnumConstant() {
throw new UnsupportedOperationException();
}
private static native long getPrimitive
(Object instance, int code, int offset);

View File

@ -0,0 +1,15 @@
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.lang.reflect;
public interface GenericDeclaration {
public TypeVariable<?>[] getTypeParameters();
}

View File

@ -19,4 +19,6 @@ public interface Member {
public int getModifiers();
public String getName();
public boolean isSynthetic();
}

View File

@ -10,7 +10,9 @@
package java.lang.reflect;
public class Method<T> extends AccessibleObject implements Member {
public class Method<T> extends AccessibleObject
implements Member, GenericDeclaration
{
private byte vmFlags;
private byte returnCode;
private byte parameterCount;
@ -124,4 +126,28 @@ public class Method<T> extends AccessibleObject implements Member {
}
throw new RuntimeException();
}
public boolean isSynthetic() {
throw new UnsupportedOperationException();
}
public Object getDefaultValue() {
throw new UnsupportedOperationException();
}
public Type[] getGenericParameterTypes() {
throw new UnsupportedOperationException();
}
public Type getGenericReturnType() {
throw new UnsupportedOperationException();
}
public Class[] getExceptionTypes() {
throw new UnsupportedOperationException();
}
public TypeVariable<Method<T>>[] getTypeParameters() {
throw new UnsupportedOperationException();
}
}

View File

@ -0,0 +1,13 @@
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.lang.reflect;
public interface Type { }

View File

@ -0,0 +1,19 @@
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.lang.reflect;
public interface TypeVariable<T extends GenericDeclaration>
extends Type
{
public Type[] getBounds();
public T getGenericDeclaration();
public String getName();
}

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
@ -11,7 +11,6 @@
package java.net;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.InputStream;
public final class URL {
@ -73,7 +72,7 @@ public final class URL {
throws MalformedURLException
{
if ("resource".equals(protocol)) {
return new ResourceHandler();
return new avian.resource.Handler();
} else {
throw new MalformedURLException("unknown protocol: " + protocol);
}
@ -88,87 +87,4 @@ public final class URL {
this.file = file;
this.ref = ref;
}
private static class ResourceHandler extends URLStreamHandler {
protected URLConnection openConnection(URL url) {
return new ResourceConnection(url);
}
}
private static class ResourceConnection extends URLConnection {
public ResourceConnection(URL url) {
super(url);
}
public int getContentLength() {
return ResourceInputStream.getContentLength(url.getFile());
}
public InputStream getInputStream() throws IOException {
return new ResourceInputStream(url.getFile());
}
}
private static class ResourceInputStream extends InputStream {
private long peer;
private int position;
public ResourceInputStream(String path) throws IOException {
peer = open(path);
if (peer == 0) {
throw new FileNotFoundException(path);
}
}
private static native int getContentLength(String path);
private static native long open(String path) throws IOException;
private static native int read(long peer, int position) throws IOException;
private static native int read(long peer, int position,
byte[] b, int offset, int length)
throws IOException;
public static native void close(long peer) throws IOException;
public int read() throws IOException {
if (peer != 0) {
int c = read(peer, position);
if (c >= 0) {
++ position;
}
return c;
} else {
throw new IOException();
}
}
public int read(byte[] b, int offset, int length) throws IOException {
if (peer != 0) {
if (b == null) {
throw new NullPointerException();
}
if (offset < 0 || offset + length > b.length) {
throw new ArrayIndexOutOfBoundsException();
}
int c = read(peer, position, b, offset, length);
if (c >= 0) {
position += c;
}
return c;
} else {
throw new IOException();
}
}
public void close() throws IOException {
if (peer != 0) {
close(peer);
peer = 0;
}
}
}
}

View File

@ -0,0 +1,13 @@
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.security;
public class AllPermission extends Permission { }

View File

@ -0,0 +1,13 @@
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.security;
public class CodeSource { }

View File

@ -0,0 +1,17 @@
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.security;
public abstract class Permission {
public PermissionCollection newPermissionCollection() {
return null;
}
}

View File

@ -0,0 +1,15 @@
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.security;
public abstract class PermissionCollection {
public abstract void add(Permission p);
}

View File

@ -0,0 +1,41 @@
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.security;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
public class Permissions extends PermissionCollection {
private final Map<Class,PermissionCollection> collections = new HashMap();
public void add(Permission p) {
Class c = p.getClass();
PermissionCollection pc = collections.get(c);
if (pc == null) {
pc = p.newPermissionCollection();
if (pc == null) {
pc = new MyPermissionCollection();
}
collections.put(c, pc);
}
pc.add(p);
}
private static class MyPermissionCollection extends PermissionCollection {
private final Set<Permission> permissions = new HashSet();
public void add(Permission p) {
permissions.add(p);
}
}
}

View File

@ -0,0 +1,23 @@
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.security;
public class ProtectionDomain {
private final CodeSource codeSource;
private final PermissionCollection permissions;
public ProtectionDomain(CodeSource codeSource,
PermissionCollection permissions)
{
this.codeSource = codeSource;
this.permissions = permissions;
}
}

View File

@ -1,34 +0,0 @@
/* Copyright (c) 2008, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.util;
public class Cell <T> {
public T value;
public Cell<T> next;
public Cell(T value, Cell<T> next) {
this.value = value;
this.next = next;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("(");
for (Cell c = this; c != null; c = c.next) {
sb.append(value);
if (c.next != null) {
sb.append(" ");
}
}
sb.append(")");
return sb.toString();
}
}

View File

@ -1,548 +0,0 @@
/* Copyright (c) 2008, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.util;
public class PersistentSet <T> implements Iterable <T> {
private static final Node NullNode = new Node(null);
static {
NullNode.left = NullNode;
NullNode.right = NullNode;
}
private final Node<T> root;
private final Comparator<T> comparator;
private final int size;
public PersistentSet() {
this(NullNode, new Comparator<T>() {
public int compare(T a, T b) {
return ((Comparable<T>) a).compareTo(b);
}
}, 0);
}
public PersistentSet(Comparator<T> comparator) {
this(NullNode, comparator, 0);
}
private PersistentSet(Node<T> root, Comparator<T> comparator, int size) {
this.root = root;
this.comparator = comparator;
this.size = size;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{");
for (java.util.Iterator it = iterator(); it.hasNext();) {
sb.append(it.next());
if (it.hasNext()) {
sb.append(",");
}
}
sb.append("}");
return sb.toString();
}
public Comparator<T> comparator() {
return comparator;
}
public PersistentSet<T> add(T value) {
return add(value, false);
}
public int size() {
return size;
}
public PersistentSet<T> add(T value, boolean replaceExisting) {
Path<T> p = find(value);
if (! p.fresh) {
if (replaceExisting) {
return p.replaceWith(value);
} else {
return this;
}
}
return add(p);
}
private PersistentSet<T> add(Path<T> p) {
if (! p.fresh) throw new IllegalArgumentException();
Node<T> new_ = p.node;
Node<T> newRoot = p.root.root;
Cell<Node<T>> ancestors = p.ancestors;
// rebalance
new_.red = true;
while (ancestors != null && ancestors.value.red) {
if (ancestors.value == ancestors.next.value.left) {
if (ancestors.next.value.right.red) {
ancestors.value.red = false;
ancestors.next.value.right = new Node(ancestors.next.value.right);
ancestors.next.value.right.red = false;
ancestors.next.value.red = true;
new_ = ancestors.next.value;
ancestors = ancestors.next.next;
} else {
if (new_ == ancestors.value.right) {
new_ = ancestors.value;
ancestors = ancestors.next;
Node<T> n = leftRotate(new_);
if (ancestors.value.right == new_) {
ancestors.value.right = n;
} else {
ancestors.value.left = n;
}
ancestors = new Cell(n, ancestors);
}
ancestors.value.red = false;
ancestors.next.value.red = true;
Node<T> n = rightRotate(ancestors.next.value);
if (ancestors.next.next == null) {
newRoot = n;
} else if (ancestors.next.next.value.right == ancestors.next.value) {
ancestors.next.next.value.right = n;
} else {
ancestors.next.next.value.left = n;
}
// done
}
} else {
if (ancestors.next.value.left.red) {
ancestors.value.red = false;
ancestors.next.value.left = new Node(ancestors.next.value.left);
ancestors.next.value.left.red = false;
ancestors.next.value.red = true;
new_ = ancestors.next.value;
ancestors = ancestors.next.next;
} else {
if (new_ == ancestors.value.left) {
new_ = ancestors.value;
ancestors = ancestors.next;
Node<T> n = rightRotate(new_);
if (ancestors.value.right == new_) {
ancestors.value.right = n;
} else {
ancestors.value.left = n;
}
ancestors = new Cell(n, ancestors);
}
ancestors.value.red = false;
ancestors.next.value.red = true;
Node<T> n = leftRotate(ancestors.next.value);
if (ancestors.next.next == null) {
newRoot = n;
} else if (ancestors.next.next.value.right == ancestors.next.value) {
ancestors.next.next.value.right = n;
} else {
ancestors.next.next.value.left = n;
}
// done
}
}
}
newRoot.red = false;
return new PersistentSet(newRoot, comparator, size + 1);
}
private static <T> Node<T> leftRotate(Node<T> n) {
Node<T> child = new Node(n.right);
n.right = child.left;
child.left = n;
return child;
}
private static <T> Node<T> rightRotate(Node<T> n) {
Node<T> child = new Node(n.left);
n.left = child.right;
child.right = n;
return child;
}
public PersistentSet<T> remove(T value) {
Path<T> p = find(value);
if (! p.fresh) {
return remove(p);
}
return this;
}
private PersistentSet<T> remove(Path<T> p) {
if (size == 1) {
if (p.node != root) {
throw new IllegalArgumentException();
}
return new PersistentSet(NullNode, comparator, 0);
}
Node<T> new_ = p.node;
Node<T> newRoot = p.root.root;
Cell<Node<T>> ancestors = p.ancestors;
Node<T> dead;
if (new_.left == NullNode || new_.right == NullNode) {
dead = new_;
} else {
Cell<Node<T>> path = successor(new_, ancestors);
dead = path.value;
ancestors = path.next;
}
Node<T> child;
if (dead.left != NullNode) {
child = dead.left;
} else {
child = dead.right;
}
if (ancestors == null) {
child.red = false;
return new PersistentSet(child, comparator, 1);
} else if (dead == ancestors.value.left) {
ancestors.value.left = child;
} else {
ancestors.value.right = child;
}
if (dead != new_) {
new_.value = dead.value;
}
if (! dead.red) {
// rebalance
while (ancestors != null && ! child.red) {
if (child == ancestors.value.left) {
Node<T> sibling = ancestors.value.right
= new Node(ancestors.value.right);
if (sibling.red) {
sibling.red = false;
ancestors.value.red = true;
Node<T> n = leftRotate(ancestors.value);
if (ancestors.next == null) {
newRoot = n;
} else if (ancestors.next.value.right == ancestors.value) {
ancestors.next.value.right = n;
} else {
ancestors.next.value.left = n;
}
ancestors.next = new Cell(n, ancestors.next);
sibling = ancestors.value.right;
}
if (! (sibling.left.red || sibling.right.red)) {
sibling.red = true;
child = ancestors.value;
ancestors = ancestors.next;
} else {
if (! sibling.right.red) {
sibling.left = new Node(sibling.left);
sibling.left.red = false;
sibling.red = true;
sibling = ancestors.value.right = rightRotate(sibling);
}
sibling.red = ancestors.value.red;
ancestors.value.red = false;
sibling.right = new Node(sibling.right);
sibling.right.red = false;
Node<T> n = leftRotate(ancestors.value);
if (ancestors.next == null) {
newRoot = n;
} else if (ancestors.next.value.right == ancestors.value) {
ancestors.next.value.right = n;
} else {
ancestors.next.value.left = n;
}
child = newRoot;
ancestors = null;
}
} else {
Node<T> sibling = ancestors.value.left
= new Node(ancestors.value.left);
if (sibling.red) {
sibling.red = false;
ancestors.value.red = true;
Node<T> n = rightRotate(ancestors.value);
if (ancestors.next == null) {
newRoot = n;
} else if (ancestors.next.value.left == ancestors.value) {
ancestors.next.value.left = n;
} else {
ancestors.next.value.right = n;
}
ancestors.next = new Cell(n, ancestors.next);
sibling = ancestors.value.left;
}
if (! (sibling.right.red || sibling.left.red)) {
sibling.red = true;
child = ancestors.value;
ancestors = ancestors.next;
} else {
if (! sibling.left.red) {
sibling.right = new Node(sibling.right);
sibling.right.red = false;
sibling.red = true;
sibling = ancestors.value.left = leftRotate(sibling);
}
sibling.red = ancestors.value.red;
ancestors.value.red = false;
sibling.left = new Node(sibling.left);
sibling.left.red = false;
Node<T> n = rightRotate(ancestors.value);
if (ancestors.next == null) {
newRoot = n;
} else if (ancestors.next.value.left == ancestors.value) {
ancestors.next.value.left = n;
} else {
ancestors.next.value.right = n;
}
child = newRoot;
ancestors = null;
}
}
}
child.red = false;
}
return new PersistentSet(newRoot, comparator, size - 1);
}
private static <T> Cell<Node<T>> minimum(Node<T> n,
Cell<Node<T>> ancestors)
{
while (n.left != NullNode) {
n.left = new Node(n.left);
ancestors = new Cell(n, ancestors);
n = n.left;
}
return new Cell(n, ancestors);
}
private static <T> Cell<Node<T>> successor(Node<T> n,
Cell<Node<T>> ancestors)
{
if (n.right != NullNode) {
n.right = new Node(n.right);
return minimum(n.right, new Cell(n, ancestors));
}
while (ancestors != null && n == ancestors.value.right) {
n = ancestors.value;
ancestors = ancestors.next;
}
return ancestors;
}
public Path<T> find(T value) {
Node<T> newRoot = new Node(root);
Cell<Node<T>> ancestors = null;
Node<T> old = root;
Node<T> new_ = newRoot;
while (old != NullNode) {
ancestors = new Cell(new_, ancestors);
int difference = comparator.compare(value, old.value);
if (difference < 0) {
old = old.left;
new_ = new_.left = new Node(old);
} else if (difference > 0) {
old = old.right;
new_ = new_.right = new Node(old);
} else {
return new Path(false, new_,
new PersistentSet(newRoot, comparator, size),
ancestors.next);
}
}
new_.value = value;
return new Path(true, new_,
new PersistentSet(newRoot, comparator, size),
ancestors);
}
public Path<T> first() {
if (root == NullNode) return null;
Node<T> newRoot = new Node(root);
Cell<Node<T>> ancestors = null;
Node<T> old = root;
Node<T> new_ = newRoot;
while (old.left != NullNode) {
ancestors = new Cell(new_, ancestors);
old = old.left;
new_ = new_.left = new Node(old);
}
return new Path(true, new_,
new PersistentSet(newRoot, comparator, size),
ancestors);
}
public Path<T> last() {
if (root == NullNode) return null;
Node<T> newRoot = new Node(root);
Cell<Node<T>> ancestors = null;
Node<T> old = root;
Node<T> new_ = newRoot;
while (old.right != NullNode) {
ancestors = new Cell(new_, ancestors);
old = old.right;
new_ = new_.right = new Node(old);
}
return new Path(true, new_,
new PersistentSet(newRoot, comparator, size),
ancestors);
}
public java.util.Iterator<T> iterator() {
return new Iterator(first());
}
private Path<T> successor(Path<T> p) {
Cell<Node<T>> s = successor(p.node, p.ancestors);
if (s == null) {
return null;
} else {
return new Path(false, s.value, p.root, s.next);
}
}
private static class Node <T> {
public T value;
public Node left;
public Node right;
public boolean red;
public Node(Node<T> basis) {
if (basis != null) {
value = basis.value;
left = basis.left;
right = basis.right;
red = basis.red;
}
}
}
public static class Path <T> {
private final boolean fresh;
private final Node<T> node;
private final PersistentSet<T> root;
private final Cell<Node<T>> ancestors;
public Path(boolean fresh, Node<T> node, PersistentSet<T> root,
Cell<Node<T>> ancestors)
{
this.fresh = fresh;
this.node = node;
this.root = root;
this.ancestors = ancestors;
}
public T value() {
return node.value;
}
public boolean fresh() {
return fresh;
}
public PersistentSet<T> root() {
return root;
}
public Path<T> successor() {
return root.successor(this);
}
public PersistentSet<T> remove() {
if (fresh) throw new IllegalStateException();
return root.remove(this);
}
public PersistentSet<T> add() {
if (! fresh) throw new IllegalStateException();
return root.add(this);
}
public PersistentSet<T> replaceWith(T value) {
if (fresh) throw new IllegalStateException();
if (root.comparator.compare(node.value, value) != 0)
throw new IllegalArgumentException();
node.value = value;
return root;
}
}
public class Iterator <T> implements java.util.Iterator <T> {
private PersistentSet.Path<T> path;
private Iterator(PersistentSet.Path<T> path) {
this.path = path;
}
private Iterator(Iterator<T> start) {
path = start.path;
}
public boolean hasNext() {
return path != null;
}
public T next() {
PersistentSet.Path<T> p = path;
path = path.successor();
return p.value();
}
public void remove() {
throw new UnsupportedOperationException();
}
}
}

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
@ -10,6 +10,9 @@
package java.util;
import avian.PersistentSet;
import avian.Cell;
public class TreeSet<T> extends AbstractSet<T> implements Collection<T> {
private PersistentSet<Cell<T>> set;
private int size;

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
@ -63,7 +63,7 @@ public class ZipFile {
return index.size();
}
public Enumeration<ZipEntry> entries() {
public Enumeration<? extends ZipEntry> entries() {
return new MyEnumeration(window, index.values().iterator());
}