mirror of
https://github.com/corda/corda.git
synced 2024-12-28 00:38:55 +00:00
more classpath classes
This commit is contained in:
parent
fd770fd884
commit
90d60b3459
19
classpath/java/lang/IllegalStateException.java
Normal file
19
classpath/java/lang/IllegalStateException.java
Normal file
@ -0,0 +1,19 @@
|
||||
package java.lang;
|
||||
|
||||
public class IllegalStateException extends RuntimeException {
|
||||
public IllegalStateException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public IllegalStateException(String message) {
|
||||
this(message, null);
|
||||
}
|
||||
|
||||
public IllegalStateException(Throwable cause) {
|
||||
this(null, cause);
|
||||
}
|
||||
|
||||
public IllegalStateException() {
|
||||
this(null, null);
|
||||
}
|
||||
}
|
9
classpath/java/lang/InheritableThreadLocal.java
Normal file
9
classpath/java/lang/InheritableThreadLocal.java
Normal file
@ -0,0 +1,9 @@
|
||||
package java.lang;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class InheritableThreadLocal<T> extends ThreadLocal<T> {
|
||||
protected T childValue(T parentValue) {
|
||||
return parentValue;
|
||||
}
|
||||
}
|
7
classpath/java/lang/Iterable.java
Normal file
7
classpath/java/lang/Iterable.java
Normal file
@ -0,0 +1,7 @@
|
||||
package java.lang;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public interface Iterable<T> {
|
||||
public Iterator<T> iterator();
|
||||
}
|
@ -12,7 +12,20 @@ public class Thread implements Runnable {
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
public synchronized native void start();
|
||||
public synchronized void start() {
|
||||
Map<ThreadLocal, Object> map = currentThread().locals;
|
||||
if (map != null) {
|
||||
for (Map.Entry<ThreadLocal, Object> e: map.entrySet()) {
|
||||
if (e.getKey() instanceof InheritableThreadLocal) {
|
||||
locals().put(e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
doStart();
|
||||
}
|
||||
|
||||
private native void doStart();
|
||||
|
||||
public void run() {
|
||||
if (task != null) {
|
||||
|
11
classpath/java/util/Collection.java
Normal file
11
classpath/java/util/Collection.java
Normal file
@ -0,0 +1,11 @@
|
||||
package java.util;
|
||||
|
||||
public interface Collection<T> extends Iterable<T> {
|
||||
public int size();
|
||||
|
||||
public boolean add(T entry);
|
||||
|
||||
public boolean remove(T entry);
|
||||
|
||||
public void clear();
|
||||
}
|
@ -118,28 +118,27 @@ public class HashMap<K, V> implements Map<K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
private Cell<K, V> putCell(K key, V value) {
|
||||
Cell<K, V> c = find(key);
|
||||
if (c == null) {
|
||||
insert(factory.make(key, value, null));
|
||||
} else {
|
||||
V old = c.getValue();
|
||||
c.setValue(value);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
public V get(K key) {
|
||||
Cell<K, V> c = find(key);
|
||||
return (c == null ? null : c.getValue());
|
||||
}
|
||||
|
||||
public V put(K key, V value) {
|
||||
Cell<K, V> c = find(key);
|
||||
if (c == null) {
|
||||
insert(factory.make(key, value, null));
|
||||
return null;
|
||||
} else {
|
||||
V old = c.getValue();
|
||||
c.setValue(value);
|
||||
return old;
|
||||
}
|
||||
}
|
||||
|
||||
public V remove(K key) {
|
||||
V old = null;
|
||||
public Cell<K, V> removeCell(K key) {
|
||||
Cell<K, V> old = null;
|
||||
if (key == null) {
|
||||
if (nullCell != null) {
|
||||
old = nullCell.getValue();
|
||||
old = nullCell;
|
||||
nullCell = null;
|
||||
-- size;
|
||||
}
|
||||
@ -149,7 +148,7 @@ public class HashMap<K, V> implements Map<K, V> {
|
||||
Cell<K, V> p = null;
|
||||
for (Cell<K, V> c = array[index]; c != null; c = c.next()) {
|
||||
if (key.equals(c.getKey())) {
|
||||
old = c.getValue();
|
||||
old = c;
|
||||
if (p == null) {
|
||||
array[index] = c.next();
|
||||
} else {
|
||||
@ -166,6 +165,28 @@ public class HashMap<K, V> implements Map<K, V> {
|
||||
return old;
|
||||
}
|
||||
|
||||
public V put(K key, V value) {
|
||||
Cell<K, V> c = putCell(key, value);
|
||||
return (c == null ? null : c.getValue());
|
||||
}
|
||||
|
||||
public V remove(K key) {
|
||||
Cell<K, V> c = removeCell(key);
|
||||
return (c == null ? null : c.getValue());
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
array = null;
|
||||
}
|
||||
|
||||
public Set<Entry<K, V>> entrySet() {
|
||||
return new MySet();
|
||||
}
|
||||
|
||||
Iterator<Entry<K, V>> iterator() {
|
||||
return new MyIterator();
|
||||
}
|
||||
|
||||
interface Cell<K, V> extends Entry<K, V> {
|
||||
public HashMap.Cell<K, V> next();
|
||||
|
||||
@ -217,4 +238,85 @@ public class HashMap<K, V> implements Map<K, V> {
|
||||
return new MyCell(key, value, next);
|
||||
}
|
||||
}
|
||||
|
||||
private class MySet implements Set<Entry<K, V>> {
|
||||
public int size() {
|
||||
return HashMap.this.size();
|
||||
}
|
||||
|
||||
public boolean add(Entry<K, V> e) {
|
||||
return putCell(e.getKey(), e.getValue()) != null;
|
||||
}
|
||||
|
||||
public boolean remove(Entry<K, V> e) {
|
||||
return removeCell(e.getKey()) != null;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
HashMap.this.clear();
|
||||
}
|
||||
|
||||
public Iterator<Entry<K, V>> iterator() {
|
||||
return new MyIterator();
|
||||
}
|
||||
}
|
||||
|
||||
private class MyIterator implements Iterator<Entry<K, V>> {
|
||||
private int currentIndex = -1;
|
||||
private int nextIndex = -1;
|
||||
private Cell<K, V> previousCell;
|
||||
private Cell<K, V> currentCell;
|
||||
private Cell<K, V> nextCell;
|
||||
|
||||
public MyIterator() {
|
||||
hasNext();
|
||||
}
|
||||
|
||||
public Entry<K, V> next() {
|
||||
if (hasNext()) {
|
||||
if (currentCell != null && currentCell.next() != null) {
|
||||
previousCell = currentCell;
|
||||
} else {
|
||||
previousCell = null;
|
||||
}
|
||||
|
||||
currentCell = nextCell;
|
||||
currentIndex = nextIndex;
|
||||
|
||||
nextCell = nextCell.next();
|
||||
|
||||
return currentCell;
|
||||
} else {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
if (array != null) {
|
||||
while (nextCell == null && ++ nextIndex < array.length) {
|
||||
if (array[nextIndex] != null) {
|
||||
nextCell = array[nextIndex];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
if (currentCell != null) {
|
||||
if (previousCell == null) {
|
||||
array[currentIndex] = currentCell.next();
|
||||
} else {
|
||||
previousCell.setNext(currentCell.next());
|
||||
if (previousCell.next() == null) {
|
||||
previousCell = null;
|
||||
}
|
||||
}
|
||||
currentCell = null;
|
||||
} else {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
55
classpath/java/util/HashSet.java
Normal file
55
classpath/java/util/HashSet.java
Normal file
@ -0,0 +1,55 @@
|
||||
package java.util;
|
||||
|
||||
public class HashSet<T> implements Set<T> {
|
||||
private static final Object Value = new Object();
|
||||
|
||||
private final HashMap<T, Object> map;
|
||||
|
||||
public HashSet(int capacity) {
|
||||
map = new HashMap(capacity);
|
||||
}
|
||||
|
||||
public HashSet() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return map.size();
|
||||
}
|
||||
|
||||
public boolean add(T element) {
|
||||
return map.put(element, Value) != Value;
|
||||
}
|
||||
|
||||
public boolean remove(T element) {
|
||||
return map.remove(element) != Value;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
map.clear();
|
||||
}
|
||||
|
||||
public Iterator<T> iterator() {
|
||||
return new MyIterator(map.iterator());
|
||||
}
|
||||
|
||||
private static class MyIterator<T> implements Iterator<T> {
|
||||
private final Iterator<Map.Entry<T, Object>> it;
|
||||
|
||||
public MyIterator(Iterator<Map.Entry<T, Object>> it) {
|
||||
this.it = it;
|
||||
}
|
||||
|
||||
public T next() {
|
||||
return it.next().getKey();
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return it.hasNext();
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
9
classpath/java/util/Iterator.java
Normal file
9
classpath/java/util/Iterator.java
Normal file
@ -0,0 +1,9 @@
|
||||
package java.util;
|
||||
|
||||
public interface Iterator<T> {
|
||||
public T next();
|
||||
|
||||
public boolean hasNext();
|
||||
|
||||
public void remove();
|
||||
}
|
@ -9,6 +9,10 @@ public interface Map<K, V> {
|
||||
|
||||
public V remove(K key);
|
||||
|
||||
public void clear();
|
||||
|
||||
public Set<Entry<K, V>> entrySet();
|
||||
|
||||
public interface Entry<K, V> {
|
||||
public K getKey();
|
||||
|
||||
|
11
classpath/java/util/NoSuchElementException.java
Normal file
11
classpath/java/util/NoSuchElementException.java
Normal file
@ -0,0 +1,11 @@
|
||||
package java.util;
|
||||
|
||||
public class NoSuchElementException extends RuntimeException {
|
||||
public NoSuchElementException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public NoSuchElementException() {
|
||||
super();
|
||||
}
|
||||
}
|
3
classpath/java/util/Set.java
Normal file
3
classpath/java/util/Set.java
Normal file
@ -0,0 +1,3 @@
|
||||
package java.util;
|
||||
|
||||
public interface Set<T> extends Collection<T> { }
|
@ -45,6 +45,14 @@ public class WeakHashMap<K, V> implements Map<K, V> {
|
||||
return map.remove(key);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
map.clear();
|
||||
}
|
||||
|
||||
public Set<Entry<K, V>> entrySet() {
|
||||
return map.entrySet();
|
||||
}
|
||||
|
||||
private static class MyCell<K, V>
|
||||
extends WeakReference<K>
|
||||
implements HashMap.Cell<K, V>
|
||||
|
@ -251,7 +251,7 @@ populate(Thread* t, object map)
|
||||
{ "Java_java_lang_Runtiime_exit",
|
||||
reinterpret_cast<void*>(exit) },
|
||||
|
||||
{ "Java_java_lang_Thread_start",
|
||||
{ "Java_java_lang_Thread_doStart",
|
||||
reinterpret_cast<void*>(start) },
|
||||
{ "Java_java_lang_Thread_currentThread",
|
||||
reinterpret_cast<void*>(currentThread) },
|
||||
|
Loading…
Reference in New Issue
Block a user