changeset 1442:bbc41b305935

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 25 Jan 2020 11:27:21 -0500
parents 83e2585104b9
children 42c07ecb0ddc
files src/luan/Luan.java
diffstat 1 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
diff -r 83e2585104b9 -r bbc41b305935 src/luan/Luan.java
--- a/src/luan/Luan.java	Fri Jan 24 12:59:20 2020 -0500
+++ b/src/luan/Luan.java	Sat Jan 25 11:27:21 2020 -0500
@@ -247,6 +247,36 @@
 		return i==n.doubleValue() ? Integer.valueOf(i) : null;
 	}
 
+	public static Long asLong(Object obj) {
+		if( obj instanceof Long )
+			return (Long)obj;
+		if( !(obj instanceof Number) )
+			return null;
+		Number n = (Number)obj;
+		long i = n.longValue();
+		return i==n.doubleValue() ? Long.valueOf(i) : null;
+	}
+
+	public static Float asFloat(Object obj) {
+		if( obj instanceof Float )
+			return (Float)obj;
+		if( !(obj instanceof Number) )
+			return null;
+		Number n = (Number)obj;
+		float i = n.floatValue();
+		return i==n.doubleValue() ? Float.valueOf(i) : null;
+	}
+
+	public static Double asDouble(Object obj) {
+		if( obj instanceof Double )
+			return (Double)obj;
+		if( !(obj instanceof Number) )
+			return null;
+		Number n = (Number)obj;
+		double i = n.doubleValue();
+		return Double.valueOf(i);
+	}
+
 	public static String stringEncode(String s) {
 		s = s.replace("\\","\\\\");
 		s = s.replace("\u0007","\\a");