Update of /var/cvs/src/org/mmbase/util
In directory james.mmbase.org:/tmp/cvs-serv7728

Modified Files:
        Casting.java 
Log Message:
some support for casting of arrays


See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/util


Index: Casting.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/util/Casting.java,v
retrieving revision 1.114
retrieving revision 1.115
diff -u -b -r1.114 -r1.115
--- Casting.java        16 Jul 2008 13:11:02 -0000      1.114
+++ Casting.java        26 Aug 2008 19:44:46 -0000      1.115
@@ -16,7 +16,7 @@
  *
  * @author Michiel Meeuwissen
  * @since  MMBase-1.6
- * @version $Id: Casting.java,v 1.114 2008/07/16 13:11:02 michiel Exp $
+ * @version $Id: Casting.java,v 1.115 2008/08/26 19:44:46 michiel Exp $
  */
 
 import java.util.*;
@@ -375,6 +375,8 @@
             return new ListWrapper((List) o, escaper);
         } else if (o instanceof byte[]) {
             return escape(escaper, new String((byte[])o));
+        } else if (o instanceof Object[]) {
+            return new ListWrapper(Arrays.asList((Object[])o), escaper);
         } else if (o instanceof String) {
             return escape(escaper, (String) o);
         } else if (o instanceof CharSequence) {
@@ -627,7 +629,18 @@
      */
     static public int toInt(Object i, int def) {
         int res = def;
-        if (i instanceof Node) {
+        if (i == null) {
+            return def;
+        } else if (i instanceof Number) {
+            long l = ((Number)i).longValue();
+            if (l > Integer.MAX_VALUE) {
+                res = Integer.MAX_VALUE;
+            } else if (l < Integer.MIN_VALUE) {
+                res = Integer.MIN_VALUE;
+            } else {
+                res = (int) l;
+            }
+        } else if (i instanceof Node) {
             res = ((Node)i).getNumber();
         } else if (i instanceof Boolean) {
             res = ((Boolean)i).booleanValue() ? 1 : 0;
@@ -643,15 +656,10 @@
             } else {
                 res = (int) timeValue;
             }
-        } else if (i instanceof Number) {
-            long l = ((Number)i).longValue();
-            if (l > Integer.MAX_VALUE) {
-                res = Integer.MAX_VALUE;
-            } else if (l < Integer.MIN_VALUE) {
-                res = Integer.MIN_VALUE;
-            } else {
-                res = (int) l;
-            }
+        } else if (i instanceof Object[]) {
+            Object[] array = (Object[]) i;
+            if (array.length == 0) return 0;
+            if (array.length >= 1) return toInt(array[0], def);
         } else if (i != null) {
             try {
                 res = Integer.parseInt("" + i);
@@ -762,6 +770,10 @@
             if (res !=- 1) res /= 1000;
         } else if (i instanceof Node) {
             res = ((Node)i).getNumber();
+        } else if (i instanceof Object[]) {
+            Object[] array = (Object[]) i;
+            if (array.length == 0) return 0;
+            if (array.length >= 1) return toLong(array[0], def);
         } else if (i != null) {
             if(i instanceof String){
                 String s = ((String)i).toLowerCase();
@@ -868,6 +880,10 @@
             if (res != -1) res = res / 1000;
         } else if (i instanceof Node) {
             res = ((Node)i).getNumber();
+        } else if (i instanceof Object[]) {
+            Object[] array = (Object[]) i;
+            if (array.length == 0) return 0;
+            if (array.length >= 1) return toDouble(array[0], def);
         } else if (i != null) {
             try {
                 res = Double.parseDouble("" + i);
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to