Better type checks

(Olof-Joachim Frahm)
parent a2cb8c41
......@@ -85,14 +85,13 @@ public final class Bignum extends LispInteger
@Override
public Object javaInstance(Class c) {
String cn = c.getName();
if (cn.equals("java.lang.Byte") || cn.equals("byte"))
if (c == Byte.class || c == byte.class)
return Byte.valueOf((byte)value.intValue());
if (cn.equals("java.lang.Short") || cn.equals("short"))
if (c == Short.class || c == short.class)
return Short.valueOf((short)value.intValue());
if (cn.equals("java.lang.Integer") || cn.equals("int"))
if (c == Integer.class || c == int.class)
return Integer.valueOf(value.intValue());
if (cn.equals("java.lang.Long") || cn.equals("long"))
if (c == Long.class || c == long.class)
return Long.valueOf((long)value.longValue());
return javaInstance();
}
......
......@@ -236,8 +236,7 @@ public final class DoubleFloat extends LispObject
@Override
public Object javaInstance(Class c)
{
String cn = c.getName();
if (cn.equals("java.lang.Float") || cn.equals("float"))
if (c == Float.class || c == float.class)
return Float.valueOf((float)value);
return javaInstance();
}
......
......@@ -76,12 +76,11 @@ public final class Fixnum extends LispInteger
@Override
public Object javaInstance(Class c)
{
String cn = c.getName();
if (cn.equals("java.lang.Byte") || cn.equals("byte"))
if (c == Byte.class || c == byte.class)
return Byte.valueOf((byte)value);
if (cn.equals("java.lang.Short") || cn.equals("short"))
if (c == Short.class || c == short.class)
return Short.valueOf((short)value);
if (cn.equals("java.lang.Long") || cn.equals("long"))
if (c == Long.class || c == long.class)
return Long.valueOf((long)value);
return javaInstance();
}
......
......@@ -132,12 +132,8 @@ public class LispObject //extends Lisp
return this;
}
String cn = c.getName();
if (cn != null) {
if (cn.equals("java.lang.Boolean") || cn.equals("boolean")) {
return Boolean.TRUE;
}
}
if (c == Boolean.class || c == boolean.class)
return Boolean.TRUE;
return error(new LispError("The value " + princToString() +
" is not of class " + c.getName()));
......
......@@ -55,13 +55,9 @@ public final class Nil extends Symbol
@Override
public Object javaInstance(Class c)
{
String cn = c.getName();
if (cn != null) {
if (cn.equals("java.lang.Boolean") || cn.equals("boolean")) {
return Boolean.FALSE;
}
}
return javaInstance();
if (c == Boolean.class || c == boolean.class)
return Boolean.FALSE;
return javaInstance();
}
@Override
......
......@@ -241,8 +241,7 @@ public final class SingleFloat extends LispObject
@Override
public Object javaInstance(Class c)
{
String cn = c.getName();
if (cn.equals("java.lang.Float") || cn.equals("float"))
if (c == Float.class || c == float.class)
return Float.valueOf(value);
return javaInstance();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment