Added several useful classes

This commit is contained in:
Eric Scharff 2007-09-26 11:27:09 -06:00
parent bd6f2913c5
commit c174ce34b6
7 changed files with 111 additions and 0 deletions

View File

@ -0,0 +1,25 @@
package java.io;
public class ByteArrayInputStream extends InputStream {
private final byte[] array;
private int position;
private final int length;
public ByteArrayInputStream(byte[] array, int offset, int length) {
this.array = array;
position = offset;
this.length = length;
}
public int read() {
if (position < length) {
return array[position++] & 0xff;
} else {
return -1;
}
}
public int available() {
returns length - position;
}
}

View File

@ -0,0 +1,38 @@
package java.lang;
import java.lang.reflect.Method;
public abstract class Enum<E extends Enum<E>> {
private final String name;
private final int ordinal;
public Enum(String name, int ordinal) {
this.name = name;
this.ordinal = ordinal;
}
public int compareTo(E other) {
return ordinal - other.ordinal;
}
public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name) {
if (name != null) {
try {
Method method = enumType.getMethod("values");
Enum values[] = (Enum[])(method.invoke(null));
for (Enum value : values) {
if (name.equals(value.name)) {
return (T) value;
}
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
return null;
}
public int ordinal() {
return ordinal;
}
}

View File

@ -0,0 +1,11 @@
package java.lang;
public class IncompatibleClassChangeError extends LinkageError {
public IncompatibleClassChangeError(String message) {
super(message);
}
public IncompatibleClassChangeError() {
super();
}
}

View File

@ -0,0 +1,11 @@
package java.lang;
public class NoSuchFieldError extends IncompatibleClassChangeError {
public NoSuchFieldError(String message) {
super(message);
}
public NoSuchFieldError() {
super();
}
}

View File

@ -0,0 +1,4 @@
package java.lang.annotation;
public interface Annotation {
}

View File

@ -0,0 +1,5 @@
package java.util;
public interface Comparator<T> {
public int compare(T o1, T o2);
}

View File

@ -0,0 +1,17 @@
package java.util;
public class Date {
public final long when;
public Date() {
when = System.currentTimeMillis();
}
public Date(long when) {
this.when = when;
}
public long getTime() {
return when;
}
}