[Schmitzm-commits] r1770 - trunk/schmitzm-core/src/main/java/de/schmitzm/temp

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Nov 3 22:06:37 CET 2011


Author: mojays
Date: 2011-11-03 22:06:37 +0100 (Thu, 03 Nov 2011)
New Revision: 1770

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/temp/BaseTypeUtil.java
Log:
BaseTypeUtil: Handling of BigDecimal

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/temp/BaseTypeUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/temp/BaseTypeUtil.java	2011-11-02 17:05:07 UTC (rev 1769)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/temp/BaseTypeUtil.java	2011-11-03 21:06:37 UTC (rev 1770)
@@ -29,6 +29,8 @@
  ******************************************************************************/
 package de.schmitzm.temp;
 
+import java.math.BigDecimal;
+
 import de.schmitzm.data.property.Properties;
 
 // nur fuer Doku
@@ -256,7 +258,23 @@
 		return o != null && isDouble(o.getClass());
 	}
 
-	/**
+    /**
+     * Prueft, ob die angegebene Klasse einen {@link BigDecimal} darstellt.
+     */
+    public static boolean isBigDecimal(Class c) {
+        return BigDecimal.class.isAssignableFrom(c);
+    }
+
+    /**
+     * Prueft, ob das angegebene Objekt einen {@link BigDecimal} darstellt.
+     * @return <code>false</code>, wenn das angegebene Objekt <code>null</code>
+     *         ist
+     */
+    public static boolean isBigDecimal(Object o) {
+        return o != null && isBigDecimal(o.getClass());
+    }
+
+    /**
 	 * Prueft, ob die angegebene Klasse einen boolschen Wert darstellt. Also
 	 * entweder <code>boolean.class</code> oder <code>java.lang.Boolean</code>.
 	 */
@@ -322,7 +340,7 @@
 	public static boolean isBaseType(Class c) {
 		return isByte(c) || isShort(c) || isInteger(c) || isLong(c)
 				|| isFloat(c) || isDouble(c) || isCharacter(c) || isString(c)
-				|| isBoolean(c);
+				|| isBigDecimal(c) || isBoolean(c);
 	}
 
 	/**
@@ -340,7 +358,7 @@
 	public static boolean isNumeric(Class c) {
 		return Number.class.isAssignableFrom(c) ||
 		       isByte(c) || isShort(c) || isInteger(c) ||
-		       isLong(c) || isFloat(c) || isDouble(c);
+		       isLong(c) || isFloat(c) || isDouble(c) || isBigDecimal(c);
 	}
 
 	/**
@@ -356,7 +374,7 @@
 	 * korrespondierende Klasse (z.B. <code>java.lang.Double</code>) darstellt.
 	 */
 	public static boolean isDecimal(Class c) {
-		return isFloat(c) || isDouble(c);
+		return isFloat(c) || isDouble(c) || isBigDecimal(c);
 	}
 
 	/**
@@ -377,6 +395,7 @@
 		return isByte(c1) && isByte(c2) || isShort(c1) && isShort(c2)
 				|| isInteger(c1) && isInteger(c2) || isLong(c1) && isLong(c2)
 				|| isFloat(c1) && isFloat(c2) || isDouble(c1) && isDouble(c2)
+				|| isBigDecimal(c1) && isBigDecimal(c2)
 				|| isBoolean(c1) && isBoolean(c2) || isCharacter(c1)
 				&& isCharacter(c2) || isString(c1) && isString(c2)
 				|| isBoolean(c1) && isBoolean(c2);
@@ -449,6 +468,8 @@
 			return source.byteValue();
 		if (Short.class.equals(destType))
 			return source.shortValue();
+		if (BigDecimal.class.equals(destType))
+		  return BigDecimal.valueOf(source.doubleValue());
 		throw new UnsupportedClassVersionError("Unsupported numeric type: "
 				+ (destType != null ? destType.getSimpleName() : "null"));
 	}
@@ -489,6 +510,8 @@
 			return (T) new Long(strValue);
 		if (isFloat(destType))
 			return (T) new Float(strValue);
+        if (isBigDecimal(destType))
+          return (T) new BigDecimal(strValue);
 		if (isDouble(destType))
 			return (T) new Double(strValue);
 		if (isBoolean(destType))



More information about the Schmitzm-commits mailing list