mirror of
https://github.com/corda/corda.git
synced 2025-02-26 11:20:44 +00:00
Merge branch 'master' of dice:git/vm
This commit is contained in:
commit
3c83d39bd8
@ -10,4 +10,20 @@ public final class Character {
|
|||||||
public char charValue() {
|
public char charValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static char toLowerCase(char c) {
|
||||||
|
if (c >= 'A' && c <= 'Z') {
|
||||||
|
return (char) ((c - 'A') + 'a');
|
||||||
|
} else {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static char toUpperCase(char c) {
|
||||||
|
if (c >= 'a' && c <= 'z') {
|
||||||
|
return (char) ((c - 'a') + 'A');
|
||||||
|
} else {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
5
classpath/java/lang/Comparable.java
Normal file
5
classpath/java/lang/Comparable.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package java.lang;
|
||||||
|
|
||||||
|
public interface Comparable<T> {
|
||||||
|
public int compareTo(T o);
|
||||||
|
}
|
@ -1,28 +1,27 @@
|
|||||||
package java.lang;
|
package java.lang;
|
||||||
|
|
||||||
public final class String {
|
public final class String implements Comparable<String> {
|
||||||
private Object data;
|
private Object data;
|
||||||
private int offset;
|
private int offset;
|
||||||
private int length;
|
private int length;
|
||||||
private int hash;
|
private int hash;
|
||||||
|
|
||||||
public String(char[] data, int offset, int length, boolean copy) {
|
public String(char[] data, int offset, int length, boolean copy) {
|
||||||
if (copy) {
|
this((Object) data, offset, length, copy);
|
||||||
char[] c = new char[length];
|
|
||||||
System.arraycopy(data, offset, c, 0, length);
|
|
||||||
|
|
||||||
this.data = c;
|
|
||||||
this.length = length;
|
|
||||||
} else {
|
|
||||||
this.data = data;
|
|
||||||
this.offset = offset;
|
|
||||||
this.length = length;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String(byte[] data, int offset, int length, boolean copy) {
|
public String(byte[] data, int offset, int length, boolean copy) {
|
||||||
|
this((Object) data, offset, length, copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String(Object data, int offset, int length, boolean copy) {
|
||||||
if (copy) {
|
if (copy) {
|
||||||
byte[] c = new byte[length];
|
Object c;
|
||||||
|
if (data instanceof char[]) {
|
||||||
|
c = new char[length];
|
||||||
|
} else {
|
||||||
|
c = new byte[length];
|
||||||
|
}
|
||||||
System.arraycopy(data, offset, c, 0, length);
|
System.arraycopy(data, offset, c, 0, length);
|
||||||
|
|
||||||
this.data = c;
|
this.data = c;
|
||||||
@ -34,19 +33,107 @@ public final class String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int length() {
|
|
||||||
return length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String valueOf(int v) {
|
public static String valueOf(int v) {
|
||||||
return valueOf((long) v);
|
return valueOf((long) v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int length() {
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
if (hash == 0) {
|
||||||
|
for (int i = 0; i < length; ++i) hash = (hash * 31) + charAt(i);
|
||||||
|
}
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
return o instanceof String && compareTo((String) o) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equalsIgnoreCase(String s) {
|
||||||
|
return compareToIgnoreCase(s) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compareTo(String s) {
|
||||||
|
int d = length - s.length;
|
||||||
|
if (d != 0) {
|
||||||
|
return d;
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < length; ++i) {
|
||||||
|
d = charAt(i) - s.charAt(i);
|
||||||
|
if (d != 0) {
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compareToIgnoreCase(String s) {
|
||||||
|
int d = length - s.length;
|
||||||
|
if (d != 0) {
|
||||||
|
return d;
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < length; ++i) {
|
||||||
|
d = Character.toLowerCase(charAt(i))
|
||||||
|
- Character.toLowerCase(s.charAt(i));
|
||||||
|
if (d != 0) {
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String substring(int start) {
|
||||||
|
return substring(start, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String substring(int start, int end) {
|
||||||
|
if (start >= 0 && end >= start && end <= length) {
|
||||||
|
if (start == 0 && end == length) {
|
||||||
|
return this;
|
||||||
|
} else if (end - start == 0) {
|
||||||
|
return "";
|
||||||
|
} else {
|
||||||
|
return new String(data, offset + start, end - start, false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean startsWith(String s) {
|
||||||
|
if (length >= s.length) {
|
||||||
|
return substring(0, s.length).compareTo(s) != 0;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean endsWith(String s) {
|
||||||
|
if (length >= s.length) {
|
||||||
|
return substring(length - s.length).compareTo(s) != 0;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String concat(String s) {
|
||||||
|
if (s.length() == 0) {
|
||||||
|
return this;
|
||||||
|
} else {
|
||||||
|
return this + s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void getChars(int srcOffset, int srcLength,
|
public void getChars(int srcOffset, int srcLength,
|
||||||
char[] dst, int dstOffset)
|
char[] dst, int dstOffset)
|
||||||
{
|
{
|
||||||
if (srcOffset + srcLength > length) {
|
if (srcOffset + srcLength > length) {
|
||||||
throw new ArrayIndexOutOfBoundsException();
|
throw new IndexOutOfBoundsException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data instanceof char[]) {
|
if (data instanceof char[]) {
|
||||||
@ -60,6 +147,18 @@ public final class String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public char charAt(int index) {
|
||||||
|
if (index < 0 || index > length) {
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data instanceof char[]) {
|
||||||
|
return ((char[]) data)[index + offset];
|
||||||
|
} else {
|
||||||
|
return (char) ((byte[]) data)[index + offset];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static String valueOf(long v) {
|
public static String valueOf(long v) {
|
||||||
if (v == 0) {
|
if (v == 0) {
|
||||||
return valueOf('0');
|
return valueOf('0');
|
||||||
|
@ -13,6 +13,8 @@ public abstract class System {
|
|||||||
|
|
||||||
public static native String getProperty(String name);
|
public static native String getProperty(String name);
|
||||||
|
|
||||||
|
public static native long currentTimeMillis();
|
||||||
|
|
||||||
public static void loadLibrary(String name) {
|
public static void loadLibrary(String name) {
|
||||||
Runtime.getRuntime().loadLibrary(name);
|
Runtime.getRuntime().loadLibrary(name);
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,15 @@ public class ArrayList<T> implements List<T> {
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean contains(T element) {
|
||||||
|
for (int i = 0; i < size; ++i) {
|
||||||
|
if (equal(element, array[i])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean add(T element) {
|
public boolean add(T element) {
|
||||||
resize();
|
resize();
|
||||||
array[size++] = element;
|
array[size++] = element;
|
||||||
|
@ -3,6 +3,10 @@ package java.util;
|
|||||||
public class Arrays {
|
public class Arrays {
|
||||||
private Arrays() { }
|
private Arrays() { }
|
||||||
|
|
||||||
|
private static boolean equal(Object a, Object b) {
|
||||||
|
return (a == null && b == null) || (a != null && a.equals(b));
|
||||||
|
}
|
||||||
|
|
||||||
public static <T> List<T> asList(final T ... array) {
|
public static <T> List<T> asList(final T ... array) {
|
||||||
return new List<T>() {
|
return new List<T>() {
|
||||||
public int size() {
|
public int size() {
|
||||||
@ -13,6 +17,15 @@ public class Arrays {
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean contains(T element) {
|
||||||
|
for (int i = 0; i < array.length; ++i) {
|
||||||
|
if (equal(element, array[i])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public T get(int index) {
|
public T get(int index) {
|
||||||
return array[index];
|
return array[index];
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@ package java.util;
|
|||||||
public interface Collection<T> extends Iterable<T> {
|
public interface Collection<T> extends Iterable<T> {
|
||||||
public int size();
|
public int size();
|
||||||
|
|
||||||
|
public boolean contains(T element);
|
||||||
|
|
||||||
public boolean add(T element);
|
public boolean add(T element);
|
||||||
|
|
||||||
public boolean remove(T element);
|
public boolean remove(T element);
|
||||||
|
@ -32,6 +32,10 @@ public class Collections {
|
|||||||
synchronized (lock) { return collection.size(); }
|
synchronized (lock) { return collection.size(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized boolean contains(T e) {
|
||||||
|
synchronized (lock) { return collection.contains(e); }
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized boolean add(T e) {
|
public synchronized boolean add(T e) {
|
||||||
synchronized (lock) { return collection.add(e); }
|
synchronized (lock) { return collection.add(e); }
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package java.util;
|
|||||||
public class HashMap<K, V> implements Map<K, V> {
|
public class HashMap<K, V> implements Map<K, V> {
|
||||||
private int size;
|
private int size;
|
||||||
private Cell[] array;
|
private Cell[] array;
|
||||||
private Cell<K, V> nullCell;
|
|
||||||
private final CellFactory factory;
|
private final CellFactory factory;
|
||||||
|
|
||||||
HashMap(int capacity, CellFactory<K, V> factory) {
|
HashMap(int capacity, CellFactory<K, V> factory) {
|
||||||
@ -31,6 +30,14 @@ public class HashMap<K, V> implements Map<K, V> {
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int hash(Object a) {
|
||||||
|
return (a == null ? 0 : a.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean equal(Object a, Object b) {
|
||||||
|
return (a == null && b == null) || (a != null && a.equals(b));
|
||||||
|
}
|
||||||
|
|
||||||
private void resize() {
|
private void resize() {
|
||||||
if (array == null || size >= array.length * 2) {
|
if (array == null || size >= array.length * 2) {
|
||||||
resize(array == null ? 16 : array.length * 2);
|
resize(array == null ? 16 : array.length * 2);
|
||||||
@ -64,58 +71,45 @@ public class HashMap<K, V> implements Map<K, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Cell<K, V> find(K key) {
|
private Cell<K, V> find(K key) {
|
||||||
if (key == null) {
|
if (array != null) {
|
||||||
return nullCell;
|
int index = hash(key) & (array.length - 1);
|
||||||
} else {
|
for (Cell<K, V> c = array[index]; c != null; c = c.next()) {
|
||||||
if (array != null) {
|
if (equal(key, c.getKey())) {
|
||||||
int index = key.hashCode() & (array.length - 1);
|
return c;
|
||||||
for (Cell<K, V> c = array[index]; c != null; c = c.next()) {
|
|
||||||
if (key.equals(c.getKey())) {
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insert(Cell<K, V> cell) {
|
private void insert(Cell<K, V> cell) {
|
||||||
++ size;
|
++ size;
|
||||||
|
|
||||||
if (cell.getKey() == null) {
|
resize();
|
||||||
nullCell = cell;
|
|
||||||
} else {
|
|
||||||
resize();
|
|
||||||
|
|
||||||
int index = cell.hashCode() & (array.length - 1);
|
int index = cell.hashCode() & (array.length - 1);
|
||||||
cell.setNext(array[index]);
|
cell.setNext(array[index]);
|
||||||
array[index] = cell;
|
array[index] = cell;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// primarily for use by WeakHashMap:
|
// primarily for use by WeakHashMap:
|
||||||
void remove(Cell<K, V> cell) {
|
void remove(Cell<K, V> cell) {
|
||||||
if (cell == nullCell) {
|
int index = cell.hashCode() & (array.length - 1);
|
||||||
nullCell = null;
|
Cell<K, V> p = null;
|
||||||
-- size;
|
for (Cell<K, V> c = array[index]; c != null; c = c.next()) {
|
||||||
} else {
|
if (c == cell) {
|
||||||
int index = cell.hashCode() & (array.length - 1);
|
if (p == null) {
|
||||||
Cell<K, V> p = null;
|
array[index] = c.next();
|
||||||
for (Cell<K, V> c = array[index]; c != null; c = c.next()) {
|
} else {
|
||||||
if (c == cell) {
|
p.setNext(c.next());
|
||||||
if (p == null) {
|
|
||||||
array[index] = c.next();
|
|
||||||
} else {
|
|
||||||
p.setNext(c.next());
|
|
||||||
}
|
|
||||||
-- size;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
-- size;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
resize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resize();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Cell<K, V> putCell(K key, V value) {
|
private Cell<K, V> putCell(K key, V value) {
|
||||||
@ -129,6 +123,14 @@ public class HashMap<K, V> implements Map<K, V> {
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean containsKey(K key) {
|
||||||
|
return find(key) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsValue(V value) {
|
||||||
|
return values().contains(value);
|
||||||
|
}
|
||||||
|
|
||||||
public V get(K key) {
|
public V get(K key) {
|
||||||
Cell<K, V> c = find(key);
|
Cell<K, V> c = find(key);
|
||||||
return (c == null ? null : c.getValue());
|
return (c == null ? null : c.getValue());
|
||||||
@ -136,31 +138,23 @@ public class HashMap<K, V> implements Map<K, V> {
|
|||||||
|
|
||||||
public Cell<K, V> removeCell(K key) {
|
public Cell<K, V> removeCell(K key) {
|
||||||
Cell<K, V> old = null;
|
Cell<K, V> old = null;
|
||||||
if (key == null) {
|
if (array != null) {
|
||||||
if (nullCell != null) {
|
int index = hash(key) & (array.length - 1);
|
||||||
old = nullCell;
|
Cell<K, V> p = null;
|
||||||
nullCell = null;
|
for (Cell<K, V> c = array[index]; c != null; c = c.next()) {
|
||||||
-- size;
|
if (equal(key, c.getKey())) {
|
||||||
}
|
old = c;
|
||||||
} else {
|
if (p == null) {
|
||||||
if (array != null) {
|
array[index] = c.next();
|
||||||
int index = key.hashCode() & (array.length - 1);
|
} else {
|
||||||
Cell<K, V> p = null;
|
p.setNext(c.next());
|
||||||
for (Cell<K, V> c = array[index]; c != null; c = c.next()) {
|
|
||||||
if (key.equals(c.getKey())) {
|
|
||||||
old = c;
|
|
||||||
if (p == null) {
|
|
||||||
array[index] = c.next();
|
|
||||||
} else {
|
|
||||||
p.setNext(c.next());
|
|
||||||
}
|
|
||||||
-- size;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
-- size;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
resize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resize();
|
||||||
}
|
}
|
||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
@ -238,7 +232,7 @@ public class HashMap<K, V> implements Map<K, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return key.hashCode();
|
return (key == null ? 0 : key.hashCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,6 +247,10 @@ public class HashMap<K, V> implements Map<K, V> {
|
|||||||
return HashMap.this.size();
|
return HashMap.this.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean contains(Entry<K, V> e) {
|
||||||
|
return containsKey(e.getKey());
|
||||||
|
}
|
||||||
|
|
||||||
public boolean add(Entry<K, V> e) {
|
public boolean add(Entry<K, V> e) {
|
||||||
return putCell(e.getKey(), e.getValue()) != null;
|
return putCell(e.getKey(), e.getValue()) != null;
|
||||||
}
|
}
|
||||||
@ -275,6 +273,10 @@ public class HashMap<K, V> implements Map<K, V> {
|
|||||||
return HashMap.this.size();
|
return HashMap.this.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean contains(K key) {
|
||||||
|
return containsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean add(K key) {
|
public boolean add(K key) {
|
||||||
return putCell(key, null) != null;
|
return putCell(key, null) != null;
|
||||||
}
|
}
|
||||||
@ -298,6 +300,10 @@ public class HashMap<K, V> implements Map<K, V> {
|
|||||||
return HashMap.this.size();
|
return HashMap.this.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean contains(V value) {
|
||||||
|
return containsValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean add(V value) {
|
public boolean add(V value) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,10 @@ public class HashSet<T> implements Set<T> {
|
|||||||
return map.size();
|
return map.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean contains(T element) {
|
||||||
|
return map.containsKey(element);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean add(T element) {
|
public boolean add(T element) {
|
||||||
return map.put(element, Value) != Value;
|
return map.put(element, Value) != Value;
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,14 @@ public class Hashtable<K, V> implements Map<K, V> {
|
|||||||
return map.size();
|
return map.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized boolean containsKey(K key) {
|
||||||
|
return map.containsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized boolean containsValue(V value) {
|
||||||
|
return map.containsValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized V get(K key) {
|
public synchronized V get(K key) {
|
||||||
return map.get(key);
|
return map.get(key);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public class LinkedList<T> implements List<T> {
|
|||||||
return (a == null && b == null) || (a != null && a.equals(b));
|
return (a == null && b == null) || (a != null && a.equals(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void add(Cell<T> c) {
|
private void addFirst(Cell<T> c) {
|
||||||
++ size;
|
++ size;
|
||||||
|
|
||||||
if (front == null) {
|
if (front == null) {
|
||||||
@ -31,6 +31,17 @@ public class LinkedList<T> implements List<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addLast(Cell<T> c) {
|
||||||
|
++ size;
|
||||||
|
|
||||||
|
if (front == null) {
|
||||||
|
front = rear = c;
|
||||||
|
} else {
|
||||||
|
c.next = front;
|
||||||
|
front = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Cell<T> find(T element) {
|
private Cell<T> find(T element) {
|
||||||
for (Cell<T> c = front; c != null; c = c.next) {
|
for (Cell<T> c = front; c != null; c = c.next) {
|
||||||
if (equal(c.value, element)) {
|
if (equal(c.value, element)) {
|
||||||
@ -60,11 +71,23 @@ public class LinkedList<T> implements List<T> {
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean contains(T element) {
|
||||||
|
return find(element) != null;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean add(T element) {
|
public boolean add(T element) {
|
||||||
add(new Cell(element, null, null));
|
addFirst(element);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addFirst(T element) {
|
||||||
|
addFirst(new Cell(element, null, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addLast(T element) {
|
||||||
|
addLast(new Cell(element, null, null));
|
||||||
|
}
|
||||||
|
|
||||||
public T get(int index) {
|
public T get(int index) {
|
||||||
return find(index).value;
|
return find(index).value;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,10 @@ package java.util;
|
|||||||
public interface Map<K, V> {
|
public interface Map<K, V> {
|
||||||
public int size();
|
public int size();
|
||||||
|
|
||||||
|
public boolean containsKey(K key);
|
||||||
|
|
||||||
|
public boolean containsValue(V value);
|
||||||
|
|
||||||
public V get(K key);
|
public V get(K key);
|
||||||
|
|
||||||
public V put(K key, V value);
|
public V put(K key, V value);
|
||||||
|
@ -15,6 +15,10 @@ public class Vector<T> implements List<T> {
|
|||||||
return list.size();
|
return list.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized boolean contains(T element) {
|
||||||
|
return list.contains(element);
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized boolean add(T element) {
|
public synchronized boolean add(T element) {
|
||||||
return list.add(element);
|
return list.add(element);
|
||||||
}
|
}
|
||||||
@ -43,6 +47,12 @@ public class Vector<T> implements List<T> {
|
|||||||
list.clear();
|
list.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized void copyInto(Object[] array) {
|
||||||
|
for (int i = 0; i < size(); ++i) {
|
||||||
|
array[i] = list.get(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Iterator<T> iterator() {
|
public Iterator<T> iterator() {
|
||||||
return new Collections.ArrayListIterator(this);
|
return new Collections.ArrayListIterator(this);
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,16 @@ public class WeakHashMap<K, V> implements Map<K, V> {
|
|||||||
return map.size();
|
return map.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean containsKey(K key) {
|
||||||
|
poll();
|
||||||
|
return map.containsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsValue(V value) {
|
||||||
|
poll();
|
||||||
|
return map.containsValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
public V get(K key) {
|
public V get(K key) {
|
||||||
poll();
|
poll();
|
||||||
return map.get(key);
|
return map.get(key);
|
||||||
@ -53,6 +63,14 @@ public class WeakHashMap<K, V> implements Map<K, V> {
|
|||||||
return map.entrySet();
|
return map.entrySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<K> keySet() {
|
||||||
|
return map.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<V> values() {
|
||||||
|
return map.values();
|
||||||
|
}
|
||||||
|
|
||||||
private static class MyCell<K, V>
|
private static class MyCell<K, V>
|
||||||
extends WeakReference<K>
|
extends WeakReference<K>
|
||||||
implements HashMap.Cell<K, V>
|
implements HashMap.Cell<K, V>
|
||||||
@ -65,7 +83,7 @@ public class WeakHashMap<K, V> implements Map<K, V> {
|
|||||||
super(key);
|
super(key);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.next = next;
|
this.next = next;
|
||||||
this.hashCode = key.hashCode();
|
this.hashCode = (key == null ? 0 : key.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public K getKey() {
|
public K getKey() {
|
||||||
|
@ -97,6 +97,12 @@ arraycopy(Thread* t, jobject src, jint srcOffset, jobject dst, jint dstOffset,
|
|||||||
t->exception = makeArrayStoreException(t);
|
t->exception = makeArrayStoreException(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jlong
|
||||||
|
currentTimeMillis(Thread* t)
|
||||||
|
{
|
||||||
|
return t->vm->system->now();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
loadLibrary(Thread* t, jobject, jstring nameString)
|
loadLibrary(Thread* t, jobject, jstring nameString)
|
||||||
{
|
{
|
||||||
|
@ -93,15 +93,6 @@ run(void* t)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t
|
|
||||||
now()
|
|
||||||
{
|
|
||||||
timeval tv = { 0, 0 };
|
|
||||||
gettimeofday(&tv, 0);
|
|
||||||
return (static_cast<int64_t>(tv.tv_sec) * 1000) +
|
|
||||||
(static_cast<int64_t>(tv.tv_usec) / 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool Verbose = false;
|
const bool Verbose = false;
|
||||||
|
|
||||||
class MySystem: public System {
|
class MySystem: public System {
|
||||||
@ -183,7 +174,7 @@ class MySystem: public System {
|
|||||||
this->depth = 0;
|
this->depth = 0;
|
||||||
this->context = 0;
|
this->context = 0;
|
||||||
if (time) {
|
if (time) {
|
||||||
int64_t then = now() + time;
|
int64_t then = s->now() + time;
|
||||||
timespec ts = { then / 1000, (then % 1000) * 1000 * 1000 };
|
timespec ts = { then / 1000, (then % 1000) * 1000 * 1000 };
|
||||||
int rv = pthread_cond_timedwait(&condition, &mutex, &ts);
|
int rv = pthread_cond_timedwait(&condition, &mutex, &ts);
|
||||||
assert(s, rv == 0);
|
assert(s, rv == 0);
|
||||||
@ -357,6 +348,13 @@ class MySystem: public System {
|
|||||||
nanosleep(&ts, 0);
|
nanosleep(&ts, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual int64_t now() {
|
||||||
|
timeval tv = { 0, 0 };
|
||||||
|
gettimeofday(&tv, 0);
|
||||||
|
return (static_cast<int64_t>(tv.tv_sec) * 1000) +
|
||||||
|
(static_cast<int64_t>(tv.tv_usec) / 1000);
|
||||||
|
}
|
||||||
|
|
||||||
virtual uint64_t call(void* function, uintptr_t* arguments, uint8_t* types,
|
virtual uint64_t call(void* function, uintptr_t* arguments, uint8_t* types,
|
||||||
unsigned count, unsigned size, unsigned returnType)
|
unsigned count, unsigned size, unsigned returnType)
|
||||||
{
|
{
|
||||||
|
@ -61,6 +61,7 @@ class System: public Allocator {
|
|||||||
virtual Status start(Runnable*) = 0;
|
virtual Status start(Runnable*) = 0;
|
||||||
virtual Status make(Monitor**) = 0;
|
virtual Status make(Monitor**) = 0;
|
||||||
virtual void sleep(int64_t milliseconds) = 0;
|
virtual void sleep(int64_t milliseconds) = 0;
|
||||||
|
virtual int64_t now() = 0;
|
||||||
virtual uint64_t call(void* function, uintptr_t* arguments, uint8_t* types,
|
virtual uint64_t call(void* function, uintptr_t* arguments, uint8_t* types,
|
||||||
unsigned count, unsigned size,
|
unsigned count, unsigned size,
|
||||||
unsigned returnType) = 0;
|
unsigned returnType) = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user