From 2e813cff1887875b094cd4996a93509e769ecc96 Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Wed, 26 Sep 2007 08:43:01 -0600 Subject: [PATCH 01/17] Added Calendar.setTime(), even though it does not work --- classpath/java/util/Calendar.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/classpath/java/util/Calendar.java b/classpath/java/util/Calendar.java index abb3236bbd..a57bf03066 100644 --- a/classpath/java/util/Calendar.java +++ b/classpath/java/util/Calendar.java @@ -34,6 +34,10 @@ public abstract class Calendar { fields[field] = value; } + public void setTime(Date date) { + // TODO + } + public abstract void roll(int field, boolean up); public void roll(int field, int amount) { From 4ae4221701983c894d87d85092c4261c619c7428 Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Wed, 26 Sep 2007 08:44:56 -0600 Subject: [PATCH 02/17] Integer should implement Comparable --- classpath/java/lang/Integer.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/classpath/java/lang/Integer.java b/classpath/java/lang/Integer.java index d30bb804b1..028d01e4e7 100644 --- a/classpath/java/lang/Integer.java +++ b/classpath/java/lang/Integer.java @@ -1,6 +1,6 @@ package java.lang; -public final class Integer extends Number { +public final class Integer extends Number implements Comparable { public static final Class TYPE = Class.forCanonicalName("I"); public static final int MIN_VALUE = 0x80000000; @@ -28,6 +28,10 @@ public final class Integer extends Number { return value; } + public int compareTo(Integer other) { + return value - other.value; + } + public String toString() { return toString(value); } From b02b98609e412f93ee0aa832bb4d39715942f023 Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Wed, 26 Sep 2007 08:57:34 -0600 Subject: [PATCH 03/17] Added methods isEmpty(), putAll(), toArray() to interfaces List and Map --- classpath/java/util/ArrayList.java | 30 +++++++++++++++++++++++- classpath/java/util/Arrays.java | 8 +++++++ classpath/java/util/HashMap.java | 10 ++++++++ classpath/java/util/Hashtable.java | 8 +++++++ classpath/java/util/IdentityHashMap.java | 8 +++++++ classpath/java/util/LinkedList.java | 21 +++++++++++++++++ classpath/java/util/List.java | 4 ++++ classpath/java/util/Map.java | 4 ++++ classpath/java/util/Vector.java | 15 ++++++++++++ classpath/java/util/WeakHashMap.java | 8 +++++++ 10 files changed, 115 insertions(+), 1 deletion(-) diff --git a/classpath/java/util/ArrayList.java b/classpath/java/util/ArrayList.java index ed48fd2328..3589f648ca 100644 --- a/classpath/java/util/ArrayList.java +++ b/classpath/java/util/ArrayList.java @@ -13,7 +13,14 @@ public class ArrayList implements List { public ArrayList() { this(0); } - + + public ArrayList(Collection source) { + this(source.size()); + for (T o : source) { + add(o); + } + } + private void grow() { if (array == null || size >= array.length) { resize(array == null ? MinimumCapacity : array.length * 2); @@ -118,6 +125,27 @@ public class ArrayList implements List { return false; } + public boolean isEmpty() { + return size() == 0; + } + + public S[] toArray(S[] a) { + Object[] retVal = null; + + if (a.length >= size) { + retVal = a; + } else { + retVal = new Object[size]; + } + for (int i = 0; i < size; ++i) { + retVal[i] = array[i]; + } + if (a.length > size) { + a[size] = null; + } + return (S[])retVal; + } + public void clear() { array = null; size = 0; diff --git a/classpath/java/util/Arrays.java b/classpath/java/util/Arrays.java index d4813a9cc8..9e6a68eed7 100644 --- a/classpath/java/util/Arrays.java +++ b/classpath/java/util/Arrays.java @@ -38,6 +38,14 @@ public class Arrays { return array[index]; } + public S[] toArray(S[] a) { + return (S[])array; + } + + public boolean isEmpty() { + return size() == 0; + } + public T remove(int index) { throw new UnsupportedOperationException(); } diff --git a/classpath/java/util/HashMap.java b/classpath/java/util/HashMap.java index e3bede0d3e..90795391ef 100644 --- a/classpath/java/util/HashMap.java +++ b/classpath/java/util/HashMap.java @@ -44,6 +44,10 @@ public class HashMap implements Map { return r; } + public boolean isEmpty() { + return size() == 0; + } + public int size() { return size; } @@ -179,6 +183,12 @@ public class HashMap implements Map { return (c == null ? null : c.getValue()); } + public void putAll(Map elts) { + for (Map.Entry entry : elts.entrySet()) { + put(entry.getKey(), entry.getValue()); + } + } + public V remove(K key) { Cell c = removeCell(key); return (c == null ? null : c.getValue()); diff --git a/classpath/java/util/Hashtable.java b/classpath/java/util/Hashtable.java index 6bfd96b68d..6701ce49c8 100644 --- a/classpath/java/util/Hashtable.java +++ b/classpath/java/util/Hashtable.java @@ -15,6 +15,10 @@ public class Hashtable implements Map { return map.toString(); } + public synchronized boolean isEmpty() { + return map.isEmpty(); + } + public synchronized int size() { return map.size(); } @@ -35,6 +39,10 @@ public class Hashtable implements Map { return map.put(key, value); } + public synchronized void putAll(Map elts) { + map.putAll(elts); + } + public synchronized V remove(K key) { return map.remove(key); } diff --git a/classpath/java/util/IdentityHashMap.java b/classpath/java/util/IdentityHashMap.java index be58d2eee9..779cb2c2ff 100644 --- a/classpath/java/util/IdentityHashMap.java +++ b/classpath/java/util/IdentityHashMap.java @@ -11,6 +11,10 @@ public class IdentityHashMap implements Map { this(0); } + public boolean isEmpty() { + return map.isEmpty(); + } + public int size() { return map.size(); } @@ -31,6 +35,10 @@ public class IdentityHashMap implements Map { return map.put(key, value); } + public void putAll(Map elts) { + map.putAll(elts); + } + public V remove(K key) { return map.remove(key); } diff --git a/classpath/java/util/LinkedList.java b/classpath/java/util/LinkedList.java index 3cfa4447e1..f0980fb982 100644 --- a/classpath/java/util/LinkedList.java +++ b/classpath/java/util/LinkedList.java @@ -73,6 +73,23 @@ public class LinkedList implements List { } } + public S[] toArray(S[] a) { + Object[] retVal = null; + if (a.length >= size) { + retVal = a; + } else { + retVal = new Object[size]; + } + int i=0; + for (Object o : this) { + retVal[i++] = o; + } + if (a.length > size) { + a[size] = null; + } + return (S[])retVal; + } + public int size() { return size; } @@ -124,6 +141,10 @@ public class LinkedList implements List { return c.value; } + public boolean isEmpty() { + return size() == 0; + } + public T removeFirst() { if (front != null) { T v = front.value; diff --git a/classpath/java/util/List.java b/classpath/java/util/List.java index d23084f657..6b0dce20f1 100644 --- a/classpath/java/util/List.java +++ b/classpath/java/util/List.java @@ -4,4 +4,8 @@ public interface List extends Collection { public T get(int index); public T remove(int index); + + public boolean isEmpty(); + + public S[] toArray(S[] a); } diff --git a/classpath/java/util/Map.java b/classpath/java/util/Map.java index f82c8386e3..218665970a 100644 --- a/classpath/java/util/Map.java +++ b/classpath/java/util/Map.java @@ -1,6 +1,8 @@ package java.util; public interface Map { + public boolean isEmpty(); + public int size(); public boolean containsKey(K key); @@ -11,6 +13,8 @@ public interface Map { public V put(K key, V value); + public void putAll(Map elts); + public V remove(K key); public void clear(); diff --git a/classpath/java/util/Vector.java b/classpath/java/util/Vector.java index 1350ce3926..c1e465f175 100644 --- a/classpath/java/util/Vector.java +++ b/classpath/java/util/Vector.java @@ -11,6 +11,13 @@ public class Vector implements List { this(0); } + public Vector(List list) { + this(list.size()); + for (T o : list) { + add(o); + } + } + public synchronized int size() { return list.size(); } @@ -39,6 +46,14 @@ public class Vector implements List { return list.remove(index); } + public synchronized boolean isEmpty() { + return list.isEmpty(); + } + + public synchronized S[] toArray(S[] a) { + return list.toArray(a); + } + public T removeElementAt(int index) { return remove(index); } diff --git a/classpath/java/util/WeakHashMap.java b/classpath/java/util/WeakHashMap.java index 22edc2c311..a6a36779f3 100644 --- a/classpath/java/util/WeakHashMap.java +++ b/classpath/java/util/WeakHashMap.java @@ -26,6 +26,10 @@ public class WeakHashMap implements Map { } } + public boolean isEmpty() { + return map.isEmpty(); + } + public int size() { return map.size(); } @@ -50,6 +54,10 @@ public class WeakHashMap implements Map { return map.put(key, value); } + public void putAll(Map elts) { + map.putAll(elts); + } + public V remove(K key) { poll(); return map.remove(key); From 876b02f64163c8687d096e8d2a1796cb83288747 Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Wed, 26 Sep 2007 09:19:21 -0600 Subject: [PATCH 04/17] Added method addAll to interface Map --- classpath/java/util/Collections.java | 9 +++++++-- classpath/java/util/HashMap.java | 8 ++++++++ classpath/java/util/Set.java | 4 +++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/classpath/java/util/Collections.java b/classpath/java/util/Collections.java index d8eda7f619..732df1f706 100644 --- a/classpath/java/util/Collections.java +++ b/classpath/java/util/Collections.java @@ -33,8 +33,8 @@ public class Collections { } static class SynchronizedCollection implements Collection { - private final Object lock; - private final Collection collection; + protected final Object lock; + protected final Collection collection; public SynchronizedCollection(Object lock, Collection collection) { this.lock = lock; @@ -73,6 +73,11 @@ public class Collections { public SynchronizedSet(Object lock, Set set) { super(lock, set); } + + public void addAll(Collection c) { + synchronized (lock) { ((Set)collection).addAll(c); } + } + } static class SynchronizedIterator implements Iterator { diff --git a/classpath/java/util/HashMap.java b/classpath/java/util/HashMap.java index 90795391ef..16337b367a 100644 --- a/classpath/java/util/HashMap.java +++ b/classpath/java/util/HashMap.java @@ -286,6 +286,10 @@ public class HashMap implements Map { return HashMap.this.size(); } + public void addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + public boolean contains(Entry e) { return containsKey(e.getKey()); } @@ -316,6 +320,10 @@ public class HashMap implements Map { return containsKey(key); } + public void addAll(Collection c) { + throw new UnsupportedOperationException(); + } + public boolean add(K key) { return putCell(key, null) != null; } diff --git a/classpath/java/util/Set.java b/classpath/java/util/Set.java index d01a5ec704..e48d1f1148 100644 --- a/classpath/java/util/Set.java +++ b/classpath/java/util/Set.java @@ -1,3 +1,5 @@ package java.util; -public interface Set extends Collection { } +public interface Set extends Collection { + public void addAll(Collection c); +} From d06d1726c417d66b644ef1765669d1fa63eafe58 Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Wed, 26 Sep 2007 09:46:38 -0600 Subject: [PATCH 05/17] Added MAX_VALUE --- classpath/java/lang/Long.java | 1 + classpath/java/lang/Short.java | 1 + 2 files changed, 2 insertions(+) diff --git a/classpath/java/lang/Long.java b/classpath/java/lang/Long.java index 913267d7bf..06c1d7506e 100644 --- a/classpath/java/lang/Long.java +++ b/classpath/java/lang/Long.java @@ -2,6 +2,7 @@ package java.lang; public final class Long extends Number { public static final Class TYPE = Class.forCanonicalName("J"); + public static final Long MAX_VALUE = 9223372036854775807l; private final long value; diff --git a/classpath/java/lang/Short.java b/classpath/java/lang/Short.java index 4b014cc207..8c3834eff6 100644 --- a/classpath/java/lang/Short.java +++ b/classpath/java/lang/Short.java @@ -2,6 +2,7 @@ package java.lang; public final class Short extends Number { public static final Class TYPE = Class.forCanonicalName("S"); + public static final short MAX_VALUE = 32767; private final short value; From cacb5a6f1ef34a01f2b0c0895bbae5bdefbbf8eb Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Wed, 26 Sep 2007 09:47:25 -0600 Subject: [PATCH 06/17] Stub method for Math.random() --- classpath/java/lang/Math.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/classpath/java/lang/Math.java b/classpath/java/lang/Math.java index ab753441c1..6ffe5879b9 100644 --- a/classpath/java/lang/Math.java +++ b/classpath/java/lang/Math.java @@ -62,6 +62,10 @@ public final class Math { return (int) Math.floor(v + 0.5); } + public static double random() { + throw new UnsupportedOperationException(); + } + public static native double floor(double v); public static native double ceil(double v); From 8c248e382f8e79c11a53cbbb20354c05a1d0c1a3 Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Wed, 26 Sep 2007 09:48:21 -0600 Subject: [PATCH 07/17] Added methods to get and set properties, and stub method to save them --- classpath/java/util/Properties.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/classpath/java/util/Properties.java b/classpath/java/util/Properties.java index 4233419bfa..41a37bc303 100644 --- a/classpath/java/util/Properties.java +++ b/classpath/java/util/Properties.java @@ -1,6 +1,7 @@ package java.util; import java.io.InputStream; +import java.io.OutputStream; import java.io.IOException; public class Properties extends Hashtable { @@ -8,6 +9,18 @@ public class Properties extends Hashtable { new Parser().parse(in, this); } + public void store(OutputStream out, String comment) throws IOException { + // TODO + } + + public String getProperty(String key) { + return (String)get(key); + } + + public void setProperty(String key, String value) { + put(key, value); + } + private static class Parser { private StringBuilder key = null; private StringBuilder value = null; From 09efe501f5034d4d46f3f9d62996054dc6d4c8eb Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Wed, 26 Sep 2007 09:48:36 -0600 Subject: [PATCH 08/17] Added TODO --- classpath/java/lang/Math.java | 1 + 1 file changed, 1 insertion(+) diff --git a/classpath/java/lang/Math.java b/classpath/java/lang/Math.java index 6ffe5879b9..2d3f2bbad4 100644 --- a/classpath/java/lang/Math.java +++ b/classpath/java/lang/Math.java @@ -63,6 +63,7 @@ public final class Math { } public static double random() { + // TODO throw new UnsupportedOperationException(); } From 0beba6cafae63f9b6ed605fd8b9aa20f6ca67738 Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Wed, 26 Sep 2007 09:48:59 -0600 Subject: [PATCH 09/17] ArrayList now implements ListIterator (for reverse traversals of lists) --- classpath/java/util/ArrayList.java | 4 ++++ classpath/java/util/Collections.java | 22 ++++++++++++++++++++-- classpath/java/util/ListIterator.java | 6 ++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 classpath/java/util/ListIterator.java diff --git a/classpath/java/util/ArrayList.java b/classpath/java/util/ArrayList.java index 3589f648ca..c069cb116a 100644 --- a/classpath/java/util/ArrayList.java +++ b/classpath/java/util/ArrayList.java @@ -154,4 +154,8 @@ public class ArrayList implements List { public Iterator iterator() { return new Collections.ArrayListIterator(this); } + + public ListIterator listIterator(int index) { + return new Collections.ArrayListIterator(this, index); + } } diff --git a/classpath/java/util/Collections.java b/classpath/java/util/Collections.java index 732df1f706..bbc4e60b3f 100644 --- a/classpath/java/util/Collections.java +++ b/classpath/java/util/Collections.java @@ -102,13 +102,31 @@ public class Collections { } } - static class ArrayListIterator implements Iterator { + static class ArrayListIterator implements ListIterator { private final List list; private boolean canRemove = false; - private int index = -1; + private int index; public ArrayListIterator(List list) { + this(list, 0); + } + + public ArrayListIterator(List list, int index) { this.list = list; + this.index = index - 1; + } + + public boolean hasPrevious() { + return index >= 0; + } + + public T previous() { + if (hasPrevious()) { + canRemove = true; + return list.get(index--); + } else { + throw new NoSuchElementException(); + } } public T next() { diff --git a/classpath/java/util/ListIterator.java b/classpath/java/util/ListIterator.java new file mode 100644 index 0000000000..126a00b716 --- /dev/null +++ b/classpath/java/util/ListIterator.java @@ -0,0 +1,6 @@ +package java.util; + +public interface ListIterator extends Iterator { + public boolean hasPrevious(); + public E previous(); +} From 7d67d09b1a62b51ce6517abdf72bd8a613873ddd Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Wed, 26 Sep 2007 09:53:30 -0600 Subject: [PATCH 10/17] Added inflate method and stub method for reset() --- classpath/java/util/zip/Inflater.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/classpath/java/util/zip/Inflater.java b/classpath/java/util/zip/Inflater.java index cb21dda892..4969f79637 100644 --- a/classpath/java/util/zip/Inflater.java +++ b/classpath/java/util/zip/Inflater.java @@ -54,6 +54,15 @@ public class Inflater { this.length = length; } + public void reset() { + // TODO + throw new UnsupportedOperationException(); + } + + public int inflate(byte[] output) throws DataFormatException { + return inflate(output, 0, output.length); + } + public int inflate(byte[] output, int offset, int length) throws DataFormatException { From 0f926f8f0bf247df3f33ebdb40468273c3964657 Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Wed, 26 Sep 2007 10:02:58 -0600 Subject: [PATCH 11/17] Added ArrayList.set --- classpath/java/util/ArrayList.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/classpath/java/util/ArrayList.java b/classpath/java/util/ArrayList.java index c069cb116a..21d2b093c3 100644 --- a/classpath/java/util/ArrayList.java +++ b/classpath/java/util/ArrayList.java @@ -100,6 +100,15 @@ public class ArrayList implements List { } } + public T set(int index, T element) { + if (index >= size) { + resize(index+1); + } + Object oldValue = array[index]; + array[index] = element; + return (T) oldValue; + } + public T remove(int index) { T v = get(index); From 219e381defc0a475b3243e19e139378b6cc15bd8 Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Wed, 26 Sep 2007 10:32:02 -0600 Subject: [PATCH 12/17] Added Long.valueOf(String) --- classpath/java/lang/Long.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/classpath/java/lang/Long.java b/classpath/java/lang/Long.java index 06c1d7506e..401d31492f 100644 --- a/classpath/java/lang/Long.java +++ b/classpath/java/lang/Long.java @@ -14,6 +14,10 @@ public final class Long extends Number { this.value = parseLong(s); } + public static Long valueOf(String value) { + return new Long(value); + } + public static Long valueOf(long value) { return new Long(value); } From 4d3fd38d54c8e976b73341bef341a11fa1843751 Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Wed, 26 Sep 2007 10:32:39 -0600 Subject: [PATCH 13/17] List now implements various forms of add() --- classpath/java/util/ArrayList.java | 7 +++++++ classpath/java/util/Arrays.java | 4 ++++ classpath/java/util/LinkedList.java | 10 ++++++++++ classpath/java/util/List.java | 4 ++++ classpath/java/util/Vector.java | 4 ++++ 5 files changed, 29 insertions(+) diff --git a/classpath/java/util/ArrayList.java b/classpath/java/util/ArrayList.java index 21d2b093c3..fa0813805c 100644 --- a/classpath/java/util/ArrayList.java +++ b/classpath/java/util/ArrayList.java @@ -67,6 +67,13 @@ public class ArrayList implements List { return false; } + public void add(int index, T element) { + size = Math.max(size+1, index+1); + grow(); + System.arraycopy(array, index, array, index+1, size-index); + array[index] = element; + } + public boolean add(T element) { ++ size; grow(); diff --git a/classpath/java/util/Arrays.java b/classpath/java/util/Arrays.java index 9e6a68eed7..204c18548e 100644 --- a/classpath/java/util/Arrays.java +++ b/classpath/java/util/Arrays.java @@ -25,6 +25,10 @@ public class Arrays { throw new UnsupportedOperationException(); } + public void add(int index, T element) { + throw new UnsupportedOperationException(); + } + public boolean contains(T element) { for (int i = 0; i < array.length; ++i) { if (equal(element, array[i])) { diff --git a/classpath/java/util/LinkedList.java b/classpath/java/util/LinkedList.java index f0980fb982..bdb9b7d589 100644 --- a/classpath/java/util/LinkedList.java +++ b/classpath/java/util/LinkedList.java @@ -107,6 +107,16 @@ public class LinkedList implements List { return true; } + public void add(int index, T element) { + if (index == 0) { + addFirst(element); + } else { + Cell cell = find(index); + Cell newCell = new Cell(element, cell.prev, cell); + cell.prev.next = newCell; + } + } + public void addFirst(T element) { addFirst(new Cell(element, null, null)); } diff --git a/classpath/java/util/List.java b/classpath/java/util/List.java index 6b0dce20f1..0c679415a8 100644 --- a/classpath/java/util/List.java +++ b/classpath/java/util/List.java @@ -5,6 +5,10 @@ public interface List extends Collection { public T remove(int index); + public boolean add(T element); + + public void add(int index, T element); + public boolean isEmpty(); public S[] toArray(S[] a); diff --git a/classpath/java/util/Vector.java b/classpath/java/util/Vector.java index c1e465f175..cf2d30f58b 100644 --- a/classpath/java/util/Vector.java +++ b/classpath/java/util/Vector.java @@ -26,6 +26,10 @@ public class Vector implements List { return list.contains(element); } + public synchronized void add(int index, T element) { + list.add(index, element); + } + public synchronized boolean add(T element) { return list.add(element); } From bd6f2913c5d803cb8094f1b0ddf4ce6c0147cd46 Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Wed, 26 Sep 2007 11:22:23 -0600 Subject: [PATCH 14/17] Runtime should implement IOException --- classpath/java/lang/Runtime.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/classpath/java/lang/Runtime.java b/classpath/java/lang/Runtime.java index f5d81402cf..ddc657ec87 100644 --- a/classpath/java/lang/Runtime.java +++ b/classpath/java/lang/Runtime.java @@ -1,5 +1,6 @@ package java.lang; +import java.io.IOException; import java.io.InputStream; import java.io.FileInputStream; import java.io.OutputStream; @@ -31,7 +32,7 @@ public class Runtime { } } - public Process exec(String command) { + public Process exec(String command) throws IOException { int[] process = new int[4]; exec(command, process); return new MyProcess(process[0], process[1], process[2], process[3]); From c174ce34b69f9ceca6dc5db1927210c80c255086 Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Wed, 26 Sep 2007 11:27:09 -0600 Subject: [PATCH 15/17] Added several useful classes --- classpath/java/io/ByteArrayInputStream.java | 25 ++++++++++++ classpath/java/lang/Enum.java | 38 +++++++++++++++++++ .../lang/IncompatibleClassChangeError.java | 11 ++++++ classpath/java/lang/NoSuchFieldError.java | 11 ++++++ .../java/lang/annotation/Annotation.java | 4 ++ classpath/java/util/Comparator.java | 5 +++ classpath/java/util/Date.java | 17 +++++++++ 7 files changed, 111 insertions(+) create mode 100644 classpath/java/io/ByteArrayInputStream.java create mode 100644 classpath/java/lang/Enum.java create mode 100644 classpath/java/lang/IncompatibleClassChangeError.java create mode 100644 classpath/java/lang/NoSuchFieldError.java create mode 100644 classpath/java/lang/annotation/Annotation.java create mode 100644 classpath/java/util/Comparator.java create mode 100644 classpath/java/util/Date.java diff --git a/classpath/java/io/ByteArrayInputStream.java b/classpath/java/io/ByteArrayInputStream.java new file mode 100644 index 0000000000..0b649e3c9b --- /dev/null +++ b/classpath/java/io/ByteArrayInputStream.java @@ -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; + } +} diff --git a/classpath/java/lang/Enum.java b/classpath/java/lang/Enum.java new file mode 100644 index 0000000000..5d9b65b655 --- /dev/null +++ b/classpath/java/lang/Enum.java @@ -0,0 +1,38 @@ +package java.lang; + +import java.lang.reflect.Method; + +public abstract class Enum> { + 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 valueOf(Class 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; + } +} diff --git a/classpath/java/lang/IncompatibleClassChangeError.java b/classpath/java/lang/IncompatibleClassChangeError.java new file mode 100644 index 0000000000..88234d574f --- /dev/null +++ b/classpath/java/lang/IncompatibleClassChangeError.java @@ -0,0 +1,11 @@ +package java.lang; + +public class IncompatibleClassChangeError extends LinkageError { + public IncompatibleClassChangeError(String message) { + super(message); + } + + public IncompatibleClassChangeError() { + super(); + } +} diff --git a/classpath/java/lang/NoSuchFieldError.java b/classpath/java/lang/NoSuchFieldError.java new file mode 100644 index 0000000000..77634a27b6 --- /dev/null +++ b/classpath/java/lang/NoSuchFieldError.java @@ -0,0 +1,11 @@ +package java.lang; + +public class NoSuchFieldError extends IncompatibleClassChangeError { + public NoSuchFieldError(String message) { + super(message); + } + + public NoSuchFieldError() { + super(); + } +} diff --git a/classpath/java/lang/annotation/Annotation.java b/classpath/java/lang/annotation/Annotation.java new file mode 100644 index 0000000000..cea69c8d4e --- /dev/null +++ b/classpath/java/lang/annotation/Annotation.java @@ -0,0 +1,4 @@ +package java.lang.annotation; + +public interface Annotation { +} diff --git a/classpath/java/util/Comparator.java b/classpath/java/util/Comparator.java new file mode 100644 index 0000000000..b7d84cda37 --- /dev/null +++ b/classpath/java/util/Comparator.java @@ -0,0 +1,5 @@ +package java.util; + +public interface Comparator { + public int compare(T o1, T o2); +} diff --git a/classpath/java/util/Date.java b/classpath/java/util/Date.java new file mode 100644 index 0000000000..6dc0372d96 --- /dev/null +++ b/classpath/java/util/Date.java @@ -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; + } +} From c7567b40812b8d1c0f7915d3bb332a8492c19e9b Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Wed, 26 Sep 2007 11:45:44 -0600 Subject: [PATCH 16/17] Fixed typo --- classpath/java/io/ByteArrayInputStream.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classpath/java/io/ByteArrayInputStream.java b/classpath/java/io/ByteArrayInputStream.java index 0b649e3c9b..ee053f4fe8 100644 --- a/classpath/java/io/ByteArrayInputStream.java +++ b/classpath/java/io/ByteArrayInputStream.java @@ -20,6 +20,6 @@ public class ByteArrayInputStream extends InputStream { } public int available() { - returns length - position; + return length - position; } } From a88f7c84736e43f3b45d589519e7c43d675ff1a7 Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Wed, 26 Sep 2007 12:59:18 -0600 Subject: [PATCH 17/17] Implemented proper enum toString() behavior and an enum test. it should work, but it fails with the current build. --- classpath/java/lang/Enum.java | 4 ++++ classpath/java/lang/Object.java | 2 +- test/Enums.java | 39 +++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 test/Enums.java diff --git a/classpath/java/lang/Enum.java b/classpath/java/lang/Enum.java index 5d9b65b655..7d8ab4fc71 100644 --- a/classpath/java/lang/Enum.java +++ b/classpath/java/lang/Enum.java @@ -35,4 +35,8 @@ public abstract class Enum> { public int ordinal() { return ordinal; } + + public String toString() { + return name; + } } diff --git a/classpath/java/lang/Object.java b/classpath/java/lang/Object.java index f98afa5bfe..3acb15833a 100644 --- a/classpath/java/lang/Object.java +++ b/classpath/java/lang/Object.java @@ -2,7 +2,7 @@ package java.lang; public class Object { protected Object clone() throws CloneNotSupportedException { - if (this instanceof Cloneable) { + if ((this instanceof Cloneable) || getClass().isArray()) { return clone(this); } else { throw new CloneNotSupportedException(getClass().getName()); diff --git a/test/Enums.java b/test/Enums.java new file mode 100644 index 0000000000..9cb397fbc3 --- /dev/null +++ b/test/Enums.java @@ -0,0 +1,39 @@ +public class Enums { + private enum Suit { CLUBS, HEARTS, SPADES, DIAMONDS }; + private enum Rank { ACE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, + NINE, TEN, JACK, QUEEN, KING }; + private enum Person { Joe(4), Mike(5) ; + private final int age; + private Person(int age) { + this.age = age; + } + public int getAge() { + return age; + } + }; + + private static void expect(boolean v) { + if (! v) throw new RuntimeException(); + } + + private static boolean checkFaceCard(Rank r) { + switch (r) { + case ACE: + case JACK: + case QUEEN: + case KING: + return true; + } + return false; + } + + public static void main(String[] args) { + expect(Suit.CLUBS.ordinal() == 0); + expect(Suit.valueOf("DIAMONDS") == Suit.DIAMONDS); + System.out.println(Suit.SPADES); + expect(Suit.values()[1] == Suit.HEARTS); + expect(!checkFaceCard(Rank.FIVE)); + expect(checkFaceCard(Rank.KING)); + expect(Person.Mike.getAge() == 5); + } +}