private static List<String> addPropertyPaths(List<String> ret, String currentPath, PropertyDescriptor propertyDescriptor) { String propertyName = propertyDescriptor.getName(); if ("class".equals(propertyName)) { return Collections.emptyList(); } Class<?> propertyType = propertyDescriptor.getPropertyType(); if (DataType.isSingleValueType(propertyType)) { if (!currentPath.isEmpty()) { currentPath += "."; } ret.add(currentPath + propertyName); } else if (DataType.isArrayOrCollection(propertyType)) { LOG.warn((currentPath.isEmpty() ? currentPath : currentPath + ".") + propertyName + ": property paths for collections not supported yet"); // TODO support for collection properties } else { currentPath += propertyName; addClassPropertyPaths(ret, currentPath, propertyType); } return ret; }
public static Object asType(Class<?> type, String string) { if (isBoolean(type)) { return Boolean.parseBoolean(string); } else if (isInteger(type)) { return Integer.parseInt(string); } else if (isLong(type)) { return Long.parseLong(string); } else if (isDouble(type)) { return Double.parseDouble(string); } else if (isFloat(type)) { return Float.parseFloat(string); } else if (isByte(type)) { return Byte.parseByte(string); } else if (isShort(type)) { return Short.parseShort(string); } else if (isBigInteger(type)) { return new BigInteger(string); } else if (isBigDecimal(type)) { return new BigDecimal(string); } else if (isCalendar(type)) { return DatatypeConverter.parseDateTime(string); } else if (isDate(type)) { if (isIsoLatin1Number(string)) { return new Date(Long.parseLong(string)); } else { } else if (isCurrency(type)) { return Currency.getInstance(string); } else if (type.isEnum()) {
/** * Determines if the given class holds only one data item. Can be useful to determine if a value should be rendered * as scalar. * * @param clazz * to check * @return true if class is scalar */ public static boolean isSingleValueType(Class<?> clazz) { boolean ret; if (isNumber(clazz) || isBoolean(clazz) || isString(clazz) || isEnum(clazz) || isDate(clazz) || isCalendar(clazz) || isCurrency(clazz) ) { ret = true; } else { ret = false; } return ret; }
private Object getContentAsScalarValue(Object content) { Object value = null; if (content == null) { value = NULL_VALUE; } else if (DataType.isSingleValueType(content.getClass())) { value = DataType.asScalarValue(content); } return value; }
public static Object asScalarValue(Object bean) { Class<?> type = bean.getClass(); if (isBigInteger(type)) { return ((BigInteger) bean).intValue(); } else if (isBigDecimal(type)) { return ((BigDecimal) bean).doubleValue(); } else if (isCalendar(type)) { return ((Calendar) bean).getTime(); } else if (isDate(type)) { return ((Date) bean).getTime(); } else if (isCurrency(type)) { return ((Currency) bean).toString(); } else { return bean; } }
private static Object getContentAsScalarValue(Object content) { final Object value; if (content == null) { value = ResourceTraversal.NULL_VALUE; } else if (DataType.isSingleValueType(content.getClass())) { value = content.toString(); } else { value = null; } return value; } }
List<String> formValue = formValues.get(parentParamName + paramName); Class<?> parameterType = parameters[paramIndex]; if (DataType.isSingleValueType(parameterType)) { if (formValue != null) { if (formValue.size() == 1) { args[paramIndex++] = DataType.asType(parameterType, formValue.get(0)); } else { List<String> strings = formValues.get(name); if (writeMethod != null && strings != null && strings.size() == 1) { writeMethod.invoke(ret, DataType.asType(propertyDescriptor.getPropertyType(), strings.get(0))
@Test public void testAsTypeDateBoolean() { assertTrue((Boolean) DataType.asType(Boolean.class, "true")); assertTrue((Boolean) DataType.asType(Boolean.class, "TRUE")); assertTrue((Boolean) DataType.asType(Boolean.class, "True")); assertFalse((Boolean) DataType.asType(Boolean.class, "false")); assertFalse((Boolean) DataType.asType(Boolean.class, "FALSE")); assertFalse((Boolean) DataType.asType(Boolean.class, "False")); assertFalse((Boolean) DataType.asType(Boolean.class, "yes")); assertFalse((Boolean) DataType.asType(Boolean.class, "foo")); assertFalse((Boolean) DataType.asType(Boolean.class, null)); }
/** * Determines if action input parameter is an array or collection. * * @return true if array or collection */ public boolean isArrayOrCollection() { if (arrayOrCollection == null) { arrayOrCollection = DataType.isArrayOrCollection(getParameterType()); } return arrayOrCollection; }
@Test public void testIsIsoLatin1Number() throws Exception { assertTrue(DataType.isIsoLatin1Number("1")); assertTrue(DataType.isIsoLatin1Number("-1")); assertTrue(DataType.isIsoLatin1Number("+1")); assertTrue(DataType.isIsoLatin1Number("123456789")); assertTrue(DataType.isIsoLatin1Number("-123456789")); assertTrue(DataType.isIsoLatin1Number("+123456789")); // not an iso latin 1 number assertFalse(DataType.isIsoLatin1Number("1+")); assertFalse(DataType.isIsoLatin1Number("1-")); assertFalse(DataType.isIsoLatin1Number("2.99792458e8")); assertFalse(DataType.isIsoLatin1Number("foo")); assertFalse(DataType.isIsoLatin1Number("")); assertFalse(DataType.isIsoLatin1Number(null)); } }
@Test public void testIsCurrency() throws Exception { Assert.assertTrue(DataType.isCurrency(Currency.class)); }
private static Object getContentAsScalarValue(Object content) { final Object value; if (content == null) { value = UberNode.NULL_VALUE; } else if (DataType.isSingleValueType(content.getClass())) { value = content.toString(); } else { value = null; } return value; }
public static Object asScalarValue(Object bean) { Class<?> type = bean.getClass(); if (isBigInteger(type)) { return ((BigInteger) bean).intValue(); } else if (isBigDecimal(type)) { return ((BigDecimal) bean).doubleValue(); } else if (isCalendar(type)) { return ((Calendar) bean).getTime(); } else if (isDate(type)) { return ((Date) bean).getTime(); } else if (isCurrency(type)) { return ((Currency) bean).toString(); } else { return bean; } }
List<String> formValue = formValues.get(parentParamName + paramName); Class<?> parameterType = parameters[paramIndex]; if (DataType.isSingleValueType(parameterType)) { if (formValue != null) { if (formValue.size() == 1) { args[paramIndex++] = DataType.asType(parameterType, formValue.get(0)); } else { List<String> strings = formValues.get(name); if (writeMethod != null && strings != null && strings.size() == 1) { writeMethod.invoke(ret, DataType.asType(propertyDescriptor.getPropertyType(), strings.get(0))
@Test public void testAsTypeNumbers() { assertEquals(12, DataType.asType(int.class, "12")); assertEquals(12, DataType.asType(Integer.class, "12")); assertEquals(12L, DataType.asType(long.class, "12")); assertEquals(12L, DataType.asType(Long.class, "12")); assertEquals(12F, DataType.asType(float.class, "12")); assertEquals(12F, DataType.asType(Float.class, "12")); assertEquals(12D, DataType.asType(double.class, "12")); assertEquals(12D, DataType.asType(Double.class, "12")); assertEquals((byte) 12, DataType.asType(byte.class, "12")); assertEquals((byte) 12, DataType.asType(Byte.class, "12")); assertEquals((short) 12, DataType.asType(short.class, "12")); assertEquals((short) 12, DataType.asType(Short.class, "12")); assertEquals(BigInteger.valueOf(12), DataType.asType(BigInteger.class, "12")); assertEquals(BigDecimal.valueOf(12), DataType.asType(BigDecimal.class, "12")); }
private Object getContentAsScalarValue(Object content) { Object value = null; if (content == null) { value = NULL_VALUE; } else if (DataType.isSingleValueType(content.getClass())) { value = DataType.asScalarValue(content); } return value; }
@Test public void testIsNumberBigDecimal() throws Exception { Assert.assertTrue(DataType.isNumber(BigDecimal.class)); }
/** * Determines if action input parameter is an array or collection. * * @return true if array or collection */ public boolean isArrayOrCollection() { if (arrayOrCollection == null) { arrayOrCollection = DataType.isArrayOrCollection(getParameterType()); } return arrayOrCollection; }