/** * This method attempts to create an object of the given "type" using the "value" parameter. e.g. * calling createObjectFromString("java.lang.Integer", "10") will return an Integer object * initialized to 10. */ public static Object createObjectFromString(String type, String value) throws Exception { Object result; if (primitiveToWrapper.containsKey(type)) { if (type.equals(Character.TYPE.getName())) { result = new Character(value.charAt(0)); } else { result = newStringConstructor(((Class<?>) primitiveToWrapper.get(type)).getName(), value); } } else if (type.equals(Character.class.getName())) { result = new Character(value.charAt(0)); } else if (Number.class.isAssignableFrom(Utils.getClass(type))) { result = createNumberFromStringValue(value); } else if (value == null || value.toString().equals("null")) { // hack for null value result = null; } else { // try to create a Java object using // the one-string-param constructor result = newStringConstructor(type, value); } return result; }
private boolean compare_PrimitiveArray( int operation, Class type, Object primarray, Object value2) { if (Integer.TYPE.isAssignableFrom(type)) { int[] array = (int[]) primarray; for (int i = 0, size = array.length; i < size; i++) { if (compare_Integer(operation, array[i], value2)) { return true; } } return false; } if (Long.TYPE.isAssignableFrom(type)) { long[] array = (long[]) primarray; for (int i = 0, size = array.length; i < size; i++) { if (compare_Long(operation, array[i], value2)) { return true; } } return false; } if (Byte.TYPE.isAssignableFrom(type)) { byte[] array = (byte[]) primarray; for (int i = 0, size = array.length; i < size; i++) { if (compare_Byte(operation, array[i], value2)) { return true; } } return false; } if (Short.TYPE.isAssignableFrom(type)) { short[] array = (short[]) primarray; for (int i = 0, size = array.length; i < size; i++) { if (compare_Short(operation, array[i], value2)) { return true; } } return false; } if (Character.TYPE.isAssignableFrom(type)) { char[] array = (char[]) primarray; for (int i = 0, size = array.length; i < size; i++) { if (compare_Character(operation, array[i], value2)) { return true; } } return false; } if (Float.TYPE.isAssignableFrom(type)) { float[] array = (float[]) primarray; for (int i = 0, size = array.length; i < size; i++) { if (compare_Float(operation, array[i], value2)) { return true; } } return false; } if (Double.TYPE.isAssignableFrom(type)) { double[] array = (double[]) primarray; for (int i = 0, size = array.length; i < size; i++) { if (compare_Double(operation, array[i], value2)) { return true; } } return false; } if (Boolean.TYPE.isAssignableFrom(type)) { boolean[] array = (boolean[]) primarray; for (int i = 0, size = array.length; i < size; i++) { if (compare_Boolean(operation, array[i], value2)) { return true; } } return false; } return false; }
private static Map<String, Class<?>> createCommonJavaClassesMap() { Map<String, Class<?>> m = new HashMap<>(); m.put("java.lang.String", java.lang.String.class); m.put("String", java.lang.String.class); m.put("java.lang.CharSequence", java.lang.CharSequence.class); m.put("CharSequence", java.lang.CharSequence.class); m.put("java.sql.Timestamp", java.sql.Timestamp.class); m.put("Timestamp", java.sql.Timestamp.class); m.put("java.sql.Time", java.sql.Time.class); m.put("Time", java.sql.Time.class); m.put("java.sql.Date", java.sql.Date.class); m.put("Date", java.sql.Date.class); m.put("java.util.Locale", java.util.Locale.class); m.put("java.util.TimeZone", java.util.TimeZone.class); m.put("java.lang.Byte", java.lang.Byte.class); m.put("java.lang.Character", java.lang.Character.class); m.put("java.lang.Integer", java.lang.Integer.class); m.put("Integer", java.lang.Integer.class); m.put("java.lang.Long", java.lang.Long.class); m.put("Long", java.lang.Long.class); m.put("java.lang.Short", java.lang.Short.class); m.put("java.lang.Float", java.lang.Float.class); m.put("Float", java.lang.Float.class); m.put("java.lang.Double", java.lang.Double.class); m.put("Double", java.lang.Double.class); m.put("java.math.BigDecimal", java.math.BigDecimal.class); m.put("BigDecimal", java.math.BigDecimal.class); m.put("java.math.BigInteger", java.math.BigInteger.class); m.put("BigInteger", java.math.BigInteger.class); m.put("java.lang.Boolean", java.lang.Boolean.class); m.put("Boolean", java.lang.Boolean.class); m.put("java.lang.Object", java.lang.Object.class); m.put("Object", java.lang.Object.class); m.put("java.sql.Blob", java.sql.Blob.class); m.put("Blob", java.sql.Blob.class); m.put("java.nio.ByteBuffer", java.nio.ByteBuffer.class); m.put("java.sql.Clob", java.sql.Clob.class); m.put("Clob", java.sql.Clob.class); m.put("java.util.Date", java.util.Date.class); m.put("java.util.Collection", java.util.Collection.class); m.put("Collection", java.util.Collection.class); m.put("java.util.List", java.util.List.class); m.put("List", java.util.List.class); m.put("java.util.ArrayList", java.util.ArrayList.class); m.put("ArrayList", java.util.ArrayList.class); m.put("java.util.Map", java.util.Map.class); m.put("Map", java.util.Map.class); m.put("java.util.HashMap", java.util.HashMap.class); m.put("java.util.Set", java.util.Set.class); m.put("Set", java.util.Set.class); m.put("java.util.HashSet", java.util.HashSet.class); m.put("groovy.util.Node", groovy.util.Node.class); m.put("Node", groovy.util.Node.class); m.put("org.moqui.util.MNode", org.moqui.util.MNode.class); m.put("MNode", org.moqui.util.MNode.class); m.put(Boolean.TYPE.getName(), Boolean.TYPE); m.put(Short.TYPE.getName(), Short.TYPE); m.put(Integer.TYPE.getName(), Integer.TYPE); m.put(Long.TYPE.getName(), Long.TYPE); m.put(Float.TYPE.getName(), Float.TYPE); m.put(Double.TYPE.getName(), Double.TYPE); m.put(Byte.TYPE.getName(), Byte.TYPE); m.put(Character.TYPE.getName(), Character.TYPE); m.put("long[]", long[].class); m.put("char[]", char[].class); return m; }