various classpath updates to help SWT build

This commit is contained in:
Joel Dice 2007-08-30 17:31:32 -06:00
parent 8b102783a6
commit a4b4f36c5b
14 changed files with 358 additions and 16 deletions

View File

@ -0,0 +1,94 @@
package java.io;
public class ByteArrayOutputStream extends OutputStream {
private static final int BufferSize = 32;
private Cell chain;
private int length;
private byte[] buffer;
private int position;
public ByteArrayOutputStream(int capacity) { }
public ByteArrayOutputStream() {
this(0);
}
public void write(int c) {
if (buffer == null) {
buffer = new byte[BufferSize];
} else if (position >= buffer.length) {
flushBuffer();
buffer = new byte[BufferSize];
}
buffer[position++] = (byte) (c & 0xFF);
++ length;
}
private byte[] copy(byte[] b, int offset, int length) {
byte[] array = new byte[length];
System.arraycopy(b, offset, array, 0, length);
return array;
}
public void write(byte[] b, int offset, int length) {
if (b == null) {
throw new NullPointerException();
}
if (offset < 0 || offset + length > b.length) {
throw new ArrayIndexOutOfBoundsException();
}
if (length == 0) return;
if (buffer != null && length <= buffer.length - position) {
System.arraycopy(b, offset, buffer, position, length);
position += length;
} else {
flushBuffer();
chain = new Cell(copy(b, offset, length), 0, length, chain);
}
this.length += length;
}
private void flushBuffer() {
if (position > 0) {
byte[] b = buffer;
int p = position;
buffer = null;
position = 0;
chain = new Cell(b, 0, p, chain);
length -= p;
}
}
public byte[] toByteArray() {
flushBuffer();
byte[] array = new byte[length];
int index = length;
for (Cell c = chain; c != null; c = c.next) {
int start = index - c.length;
System.arraycopy(c.array, c.offset, array, start, c.length);
index = start;
}
return array;
}
private static class Cell {
public byte[] array;
public int offset;
public int length;
public Cell next;
public Cell(byte[] array, int offset, int length, Cell next) {
this.array = array;
this.offset = offset;
this.length = length;
this.next = next;
}
}
}

View File

@ -21,12 +21,12 @@ public class FileOutputStream extends OutputStream {
private static native int open(String path) throws IOException;
public static native void write(int fd, int c) throws IOException;
private static native void write(int fd, int c) throws IOException;
public static native void write(int fd, byte[] b, int offset, int length)
private static native void write(int fd, byte[] b, int offset, int length)
throws IOException;
public static native void close(int fd) throws IOException;
private static native void close(int fd) throws IOException;
public void write(int c) throws IOException {
write(fd, c);

View File

@ -23,5 +23,24 @@ public abstract class InputStream {
return length;
}
public long skip(long count) throws IOException {
final long Max = 8 * 1024;
int size = (int) (count < Max ? count : Max);
byte[] buffer = new byte[size];
long remaining = count;
int c;
while ((c = read(buffer, 0, (int) (size < remaining ? size : remaining)))
>= 0
&& remaining > 0)
{
remaining -= c;
}
return count - remaining;
}
public int available() throws IOException {
return 0;
}
public void close() throws IOException { }
}

View File

@ -16,6 +16,10 @@ public final class Boolean {
return (value ? Boolean.TRUE : Boolean.FALSE);
}
public static Boolean valueOf(String s) {
return ("true".equals(s) ? Boolean.TRUE : Boolean.FALSE);
}
public boolean equals(Object o) {
return o instanceof Boolean && ((Boolean) o).value == value;
}

View File

@ -4,6 +4,7 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.InvocationTargetException;
public final class Class <T> {
private static final int PrimitiveFlag = 1 << 4;
@ -37,6 +38,18 @@ public final class Class <T> {
return staticTable;
}
public T newInstance()
throws IllegalAccessException, InstantiationException
{
try {
return (T) getConstructor().newInstance();
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
}
public static Class forName(String name) throws ClassNotFoundException {
return forName
(name, true, Method.getCaller().getDeclaringClass().getClassLoader());

View File

@ -3,6 +3,10 @@ package java.lang;
public final class Double extends Number {
public static final Class TYPE = Class.forCanonicalName("D");
public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
public static final double POSITIVE_INFINITY = 1.0 / 0.0;
public static final double NaN = 0.0 / 0.0;
private final double value;
public Double(String value) {

View File

@ -36,6 +36,10 @@ public final class Integer extends Number {
return toString(v, 10);
}
public static String toHexString(int v) {
return toString(v, 16);
}
public byte byteValue() {
return (byte) value;
}

View File

@ -3,6 +3,38 @@ package java.lang;
public final class Math {
private Math() { }
public static double max(double a, double b) {
return (a < b ? b : a);
}
public static double min(double a, double b) {
return (a > b ? b : a);
}
public static float max(float a, float b) {
return (a < b ? b : a);
}
public static float min(float a, float b) {
return (a > b ? b : a);
}
public static long max(long a, long b) {
return (a < b ? b : a);
}
public static long min(long a, long b) {
return (a > b ? b : a);
}
public static int max(int a, int b) {
return (a < b ? b : a);
}
public static int min(int a, int b) {
return (a > b ? b : a);
}
public static int abs(int v) {
return (v < 0 ? -v : v);
}
@ -20,11 +52,11 @@ public final class Math {
}
public static long round(double v) {
return (long) (v + 0.5);
return (long) Math.floor(v + 0.5);
}
public static int round(float v) {
return (int) (v + 0.5);
return (int) Math.floor(v + 0.5);
}
public static native double floor(double v);

View File

@ -27,9 +27,9 @@ public class Object {
public native String toString();
public final void wait() {
public final void wait() throws InterruptedException {
wait(0);
}
public native final void wait(long timeout);
public native final void wait(long timeout) throws InterruptedException;
}

View File

@ -121,8 +121,54 @@ public final class String implements Comparable<String> {
}
}
public int indexOf(int c) {
public String trim() {
int start = -1;
for (int i = 0; i < length; ++i) {
char c = charAt(i);
if (start == -1 && ! Character.isWhitespace(c)) {
start = i;
break;
}
}
int end = -1;
for (int i = length - 1; i >= 0; --i) {
char c = charAt(i);
if (end == -1 && ! Character.isWhitespace(c)) {
end = i + 1;
break;
}
}
if (start >= end) {
return "";
} else {
return substring(start, end);
}
}
public String toLowerCase() {
char[] b = new char[length];
for (int i = 0; i < length; ++i) {
b[i] = Character.toLowerCase(charAt(i));
}
return new String(b, 0, length, false);
}
public String toUpperCase() {
char[] b = new char[length];
for (int i = 0; i < length; ++i) {
b[i] = Character.toUpperCase(charAt(i));
}
return new String(b, 0, length, false);
}
public int indexOf(int c) {
return indexOf(c, 0);
}
public int indexOf(int c, int start) {
for (int i = start; i < length; ++i) {
if (charAt(i) == c) {
return i;
}
@ -142,9 +188,13 @@ public final class String implements Comparable<String> {
}
public int indexOf(String s) {
if (s.length == 0) return 0;
return indexOf(s, 0);
}
for (int i = 0; i < length - s.length + 1; ++i) {
public int indexOf(String s, int start) {
if (s.length == 0) return start;
for (int i = start; i < length - s.length + 1; ++i) {
int j = 0;
for (; j < s.length; ++j) {
if (charAt(i + j) != s.charAt(j)) {
@ -282,6 +332,10 @@ public final class String implements Comparable<String> {
public native String intern();
public static String valueOf(Object s) {
return s.toString();
}
public static String valueOf(boolean v) {
return Boolean.toString(v);
}

View File

@ -3,6 +3,10 @@ package java.lang;
public class StringBuffer {
private final StringBuilder sb;
public StringBuffer(String s) {
sb = new StringBuilder(s);
}
public StringBuffer(int capacity) {
sb = new StringBuilder(capacity);
}
@ -36,11 +40,25 @@ public class StringBuffer {
return this;
}
public synchronized StringBuffer append(char[] b, int offset, int length) {
sb.append(b, offset, length);
return this;
}
public synchronized StringBuffer insert(int i, String s) {
sb.insert(i, s);
return this;
}
public synchronized StringBuffer deleteCharAt(int i) {
sb.deleteCharAt(i);
return this;
}
public synchronized char charAt(int i) {
return sb.charAt(i);
}
public synchronized int length() {
return sb.length();
}

View File

@ -1,11 +1,17 @@
package java.lang;
public class StringBuilder {
private static final int BufferSize = 32;
private Cell chain;
private int length;
private char[] buffer;
private int position;
public StringBuilder(String s) {
append(s);
}
public StringBuilder(int capacity) { }
public StringBuilder() {
@ -28,8 +34,13 @@ public class StringBuilder {
return append("null");
} else {
if (s.length() > 0) {
if (buffer != null && s.length() <= buffer.length - position) {
s.getChars(0, s.length(), buffer, position);
position += s.length();
} else {
flush();
chain = new Cell(s, chain);
}
length += s.length();
}
return this;
@ -46,10 +57,10 @@ public class StringBuilder {
public StringBuilder append(char v) {
if (buffer == null) {
buffer = new char[32];
buffer = new char[BufferSize];
} else if (position >= buffer.length) {
flush();
buffer = new char[32];
buffer = new char[BufferSize];
}
buffer[position++] = v;
@ -70,6 +81,60 @@ public class StringBuilder {
return append(String.valueOf(v));
}
public char charAt(int i) {
if (i < 0 || i >= length) {
throw new IndexOutOfBoundsException();
}
flush();
int index = length;
-- length;
Cell p = null;
for (Cell c = chain; c != null; c = c.next) {
int start = index - c.value.length();
index = start;
if (i >= start) {
return c.value.charAt(i - start);
}
}
throw new RuntimeException();
}
public StringBuilder insert(int i, String s) {
if (i < 0 || i >= length) {
throw new IndexOutOfBoundsException();
}
if (i == length) {
append(s);
} else {
flush();
int index = length;
-- length;
for (Cell c = chain; c != null; c = c.next) {
int start = index - c.value.length();
index = start;
if (i >= start) {
if (i == start) {
c.next = new Cell(s, c.next);
} else {
String v = c.value;
c.value = v.substring(i - start, v.length());
c.next = new Cell(s, new Cell(v.substring(0, i - start), c.next));
}
break;
}
}
}
return this;
}
public StringBuilder deleteCharAt(int i) {
if (i < 0 || i >= length) {
throw new IndexOutOfBoundsException();
@ -96,8 +161,9 @@ public class StringBuilder {
} else if (i == start + c.value.length() - 1) {
c.value = c.value.substring(0, c.value.length() - 1);
} else {
c.value = c.value.substring(i + 1, c.value.length());
c.next = new Cell(c.value.substring(0, i), c.next);
String v = c.value;
c.value = v.substring(i - start + 1, v.length());
c.next = new Cell(v.substring(0, i - start), c.next);
}
break;
}

View File

@ -67,6 +67,24 @@ public class ArrayList<T> implements List<T> {
return true;
}
public int indexOf(T element) {
for (int i = 0; i < size; ++i) {
if (equal(element, array[i])) {
return i;
}
}
return -1;
}
public int lastIndexOf(T element) {
for (int i = size; i >= 0; --i) {
if (equal(element, array[i])) {
return i;
}
}
return -1;
}
public T get(int index) {
if (index >= 0 && index < size) {
return (T) array[index];

View File

@ -39,14 +39,30 @@ public class Vector<T> implements List<T> {
return list.remove(index);
}
public T removeElementAt(int index) {
return remove(index);
}
public synchronized boolean remove(T element) {
return list.remove(element);
}
public boolean removeElement(T element) {
return remove(element);
}
public synchronized void clear() {
list.clear();
}
public synchronized int indexOf(T element) {
return list.indexOf(element);
}
public synchronized int lastIndexOf(T element) {
return list.lastIndexOf(element);
}
public synchronized void copyInto(Object[] array) {
for (int i = 0; i < size(); ++i) {
array[i] = list.get(i);