mirror of
https://github.com/corda/corda.git
synced 2025-06-17 22:58:19 +00:00
bugfixes
This commit is contained in:
@ -1,6 +1,10 @@
|
||||
package java.io;
|
||||
|
||||
public class File {
|
||||
static {
|
||||
System.loadLibrary("natives");
|
||||
}
|
||||
|
||||
private final String path;
|
||||
|
||||
public File(String path) {
|
||||
|
@ -1,6 +1,10 @@
|
||||
package java.io;
|
||||
|
||||
public class FileInputStream extends InputStream {
|
||||
static {
|
||||
System.loadLibrary("natives");
|
||||
}
|
||||
|
||||
private int fd;
|
||||
|
||||
public FileInputStream(FileDescriptor fd) {
|
||||
|
@ -1,6 +1,10 @@
|
||||
package java.io;
|
||||
|
||||
public class FileOutputStream extends OutputStream {
|
||||
static {
|
||||
System.loadLibrary("natives");
|
||||
}
|
||||
|
||||
private int fd;
|
||||
|
||||
public FileOutputStream(FileDescriptor fd) {
|
||||
|
@ -1,7 +1,15 @@
|
||||
package java.lang;
|
||||
|
||||
public class Object {
|
||||
protected native Object clone() throws CloneNotSupportedException;
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
if (this instanceof Cloneable) {
|
||||
return clone(this);
|
||||
} else {
|
||||
throw new CloneNotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
private static native Object clone(Object o);
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return this == o;
|
||||
|
@ -31,6 +31,18 @@ public final class String implements Comparable<String> {
|
||||
}
|
||||
|
||||
private String(Object data, int offset, int length, boolean copy) {
|
||||
int l;
|
||||
if (data instanceof char[]) {
|
||||
l = ((char[]) data).length;
|
||||
} else {
|
||||
l = ((byte[]) data).length;
|
||||
}
|
||||
|
||||
if (offset < 0 || offset + length > l) {
|
||||
throw new IndexOutOfBoundsException
|
||||
(offset + " < 0 or " + offset + " + " + length + " > " + l);
|
||||
}
|
||||
|
||||
if (copy) {
|
||||
Object c;
|
||||
if (data instanceof char[]) {
|
||||
@ -59,7 +71,9 @@ public final class String implements Comparable<String> {
|
||||
|
||||
public int hashCode() {
|
||||
if (hash == 0) {
|
||||
for (int i = 0; i < length; ++i) hash = (hash * 31) + charAt(i);
|
||||
int h = 0;
|
||||
for (int i = 0; i < length; ++i) h = (h * 31) + charAt(i);
|
||||
hash = h;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
@ -21,6 +21,11 @@ public class StringBuffer {
|
||||
return this;
|
||||
}
|
||||
|
||||
public synchronized StringBuffer append(char v) {
|
||||
sb.append(v);
|
||||
return this;
|
||||
}
|
||||
|
||||
public synchronized StringBuffer append(int v) {
|
||||
sb.append(v);
|
||||
return this;
|
||||
|
@ -3,6 +3,8 @@ package java.lang;
|
||||
public class StringBuilder {
|
||||
private Cell chain;
|
||||
private int length;
|
||||
private char[] buffer;
|
||||
private int position;
|
||||
|
||||
public StringBuilder(int capacity) { }
|
||||
|
||||
@ -10,12 +12,28 @@ public class StringBuilder {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public StringBuilder append(String s) {
|
||||
if (s.length() > 0) {
|
||||
chain = new Cell(s, chain);
|
||||
length += s.length();
|
||||
private void flush() {
|
||||
if (position > 0) {
|
||||
char[] b = buffer;
|
||||
int p = position;
|
||||
buffer = null;
|
||||
position = 0;
|
||||
append(new String(b, 0, p, false));
|
||||
length -= p;
|
||||
}
|
||||
}
|
||||
|
||||
public StringBuilder append(String s) {
|
||||
if (s == null) {
|
||||
return append("null");
|
||||
} else {
|
||||
if (s.length() > 0) {
|
||||
flush();
|
||||
chain = new Cell(s, chain);
|
||||
length += s.length();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public StringBuilder append(char[] b, int offset, int length) {
|
||||
@ -26,6 +44,20 @@ public class StringBuilder {
|
||||
return append(o == null ? "null" : o.toString());
|
||||
}
|
||||
|
||||
public StringBuilder append(char v) {
|
||||
if (buffer == null) {
|
||||
buffer = new char[32];
|
||||
} else if (position >= buffer.length) {
|
||||
flush();
|
||||
buffer = new char[32];
|
||||
}
|
||||
|
||||
buffer[position++] = v;
|
||||
++ length;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public StringBuilder append(int v) {
|
||||
return append(String.valueOf(v));
|
||||
}
|
||||
@ -39,6 +71,8 @@ public class StringBuilder {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
flush();
|
||||
|
||||
int index = length;
|
||||
-- length;
|
||||
Cell p = null;
|
||||
@ -83,6 +117,8 @@ public class StringBuilder {
|
||||
return;
|
||||
}
|
||||
|
||||
flush();
|
||||
|
||||
int index = length;
|
||||
length = v;
|
||||
for (Cell c = chain; c != null; c = c.next) {
|
||||
@ -106,6 +142,8 @@ public class StringBuilder {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
flush();
|
||||
|
||||
int index = length;
|
||||
for (Cell c = chain; c != null; c = c.next) {
|
||||
int start = index - c.value.length();
|
||||
@ -124,7 +162,7 @@ public class StringBuilder {
|
||||
c.value.getChars(start - index, end - start,
|
||||
dst, dstOffset + (start - srcOffset));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
@ -5,7 +5,7 @@ public class HashMap<K, V> implements Map<K, V> {
|
||||
private Cell[] array;
|
||||
private final Helper helper;
|
||||
|
||||
HashMap(int capacity, Helper<K, V> helper) {
|
||||
public HashMap(int capacity, Helper<K, V> helper) {
|
||||
if (capacity > 0) {
|
||||
array = new Cell[nextPowerOfTwo(capacity)];
|
||||
}
|
||||
@ -20,6 +20,22 @@ public class HashMap<K, V> implements Map<K, V> {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{");
|
||||
for (Iterator<Entry<K, V>> it = iterator(); it.hasNext();) {
|
||||
Entry<K, V> e = it.next();
|
||||
sb.append(e.getKey())
|
||||
.append("=")
|
||||
.append(e.getValue());
|
||||
if (it.hasNext()) {
|
||||
sb.append(",");
|
||||
}
|
||||
}
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static int nextPowerOfTwo(int n) {
|
||||
int r = 1;
|
||||
while (r < n) r <<= 1;
|
||||
@ -85,8 +101,7 @@ public class HashMap<K, V> implements Map<K, V> {
|
||||
array[index] = cell;
|
||||
}
|
||||
|
||||
// primarily for use by WeakHashMap:
|
||||
void remove(Cell<K, V> cell) {
|
||||
public void remove(Cell<K, V> cell) {
|
||||
int index = cell.hashCode() & (array.length - 1);
|
||||
Cell<K, V> p = null;
|
||||
for (Cell<K, V> c = array[index]; c != null; c = c.next()) {
|
||||
@ -366,7 +381,7 @@ public class HashMap<K, V> implements Map<K, V> {
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return nextCell != null;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
|
Reference in New Issue
Block a user