Merge pull request #87 from dscho/beanshell

Support running Beanshell's bsh.Interpreter class
This commit is contained in:
Joshua Warner 2013-10-25 14:01:24 -07:00
commit c2203c6815
10 changed files with 65 additions and 3 deletions

View File

@ -59,6 +59,10 @@ public final class Boolean implements Comparable<Boolean> {
return value;
}
public static boolean getBoolean(String name) {
return parseBoolean(System.getProperty(name));
}
public static boolean parseBoolean(String string) {
return string != null && string.equalsIgnoreCase("true");
}

View File

@ -122,4 +122,21 @@ public final class Integer extends Number implements Comparable<Integer> {
public static int parseInt(String s, int radix) {
return (int) Long.parseLong(s, radix);
}
public static Integer decode(String string) {
if (string.startsWith("-")) {
if (string.startsWith("-0") || string.startsWith("-#")) {
return new Integer(-decode(string.substring(1)));
}
} else if (string.startsWith("0")) {
char c = string.length() < 2 ? (char)-1 : string.charAt(1);
if (c == 'x' || c == 'X') {
return new Integer(parseInt(string.substring(2), 0x10));
}
return new Integer(parseInt(string, 010));
} else if (string.startsWith("#")) {
return new Integer(parseInt(string.substring(1), 0x10));
}
return new Integer(parseInt(string, 10));
}
}

View File

@ -602,6 +602,9 @@ public final class String
}
public int lastIndexOf(int ch, int lastIndex) {
if (lastIndex >= length) {
lastIndex = length - 1;
}
for (int i = lastIndex ; i >= 0; --i) {
if (charAt(i) == ch) {
return i;

View File

@ -138,4 +138,8 @@ public class Method<T> extends AccessibleObject implements Member {
public Annotation[] getDeclaredAnnotations() {
return getAnnotations();
}
public boolean isVarArgs() {
return (getModifiers() & 0x80) != 0;
}
}

View File

@ -245,6 +245,10 @@ public class Collections {
}
}
public static <V> Set<V> synchronizedSet(Set<V> set) {
return new SynchronizedSet<V> (new Object(), set);
}
static class SynchronizedIterator<T> implements Iterator<T> {
private final Object lock;
private final Iterator<T> it;
@ -655,4 +659,10 @@ public class Collections {
return - cmp.compare(o1, o2);
}
}
public static <T> List<T> singletonList(T o) {
ArrayList<T> list = new ArrayList<T>(1);
list.add(o);
return new UnmodifiableList(list);
}
}

View File

@ -10,7 +10,7 @@
package java.util;
public class Vector<T> extends AbstractList<T> implements java.io.Serializable {
public class Vector<T> extends AbstractList<T> implements java.io.Serializable, Cloneable {
private final ArrayList<T> list;
public Vector(int capacity) {
@ -126,5 +126,12 @@ public class Vector<T> extends AbstractList<T> implements java.io.Serializable {
public Enumeration<T> elements() {
return new Collections.IteratorEnumeration(iterator());
}
public synchronized Object clone() {
Vector copy = new Vector(size());
for (T t : this) {
copy.add(t);
}
return copy;
}
}

View File

@ -2512,7 +2512,11 @@ makeArrayClass(Thread* t, object loader, object spec, bool throw_,
++ s;
const char* elementSpecStart = s;
while (*s and *s != ';') ++ s;
if (dimensions > 1) {
elementSpecStart -= dimensions;
++ s;
}
elementSpec = makeByteArray(t, s - elementSpecStart + 1);
memcpy(&byteArrayBody(t, elementSpec, 0),
&byteArrayBody(t, spec, elementSpecStart - start),

View File

@ -314,5 +314,11 @@ public class Integers {
{ int b = 0xBE; int x = 0; int y = 0xFF;
expect(((b >>> x) & y) == 0xBE); }
expect(123 == Integer.decode("123").intValue());
expect(-123 == Integer.decode("-123").intValue());
expect(-83 == Integer.decode("-0123").intValue());
expect(-291 == Integer.decode("-0x123").intValue());
expect(291 == Integer.decode("#123").intValue());
}
}

View File

@ -67,5 +67,10 @@ public class Reflection {
expect(7.0 == (Double) Reflection.class.getMethod
("doubleMethod").invoke(null));
Class[][] array = new Class[][] { { Class.class } };
expect("[Ljava.lang.Class;".equals(array[0].getClass().getName()));
expect(Class[].class == array[0].getClass());
expect(array.getClass().getComponentType() == array[0].getClass());
}
}

View File

@ -203,6 +203,8 @@ public class Strings {
System.getProperty("line.separator").getBytes())));
}
expect("abc".lastIndexOf('b', 100) == 1);
testTrivialPattern();
}
}