svn commit: r1372738 - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1372738 - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java

adrianc
Author: adrianc
Date: Tue Aug 14 06:02:58 2012
New Revision: 1372738

URL: http://svn.apache.org/viewvc?rev=1372738&view=rev
Log:
Small GenericEntity optimization - remove instanceof checks in getXxx methods.

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java?rev=1372738&r1=1372737&r2=1372738&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java Tue Aug 14 06:02:58 2012
@@ -619,14 +619,8 @@ public class GenericEntity extends Obser
     }
 
     public String getString(String name) {
-        // might be nice to add some ClassCastException handling... and auto conversion? hmmm...
         Object object = get(name);
-        if (object == null) return null;
-        if (object instanceof java.lang.String) {
-            return (String) object;
-        } else {
-            return object.toString();
-        }
+        return object == null ? null : object.toString();
     }
 
     public java.sql.Timestamp getTimestamp(String name) {
@@ -656,22 +650,28 @@ public class GenericEntity extends Obser
     public Double getDouble(String name) {
         // this "hack" is needed for now until the Double/BigDecimal issues are all resolved
         Object value = get(name);
-        if (value instanceof BigDecimal) {
-            return Double.valueOf(((BigDecimal) value).doubleValue());
-        } else {
-            return (Double) value;
+        if (value != null) {
+            try {
+                BigDecimal numValue = (BigDecimal) value;
+                return new Double(numValue.doubleValue());
+            } catch (ClassCastException e) {
+            }
         }
+        return (Double) value;
     }
 
     public BigDecimal getBigDecimal(String name) {
         // this "hack" is needed for now until the Double/BigDecimal issues are all resolved
         // NOTE: for things to generally work properly BigDecimal should really be used as the java-type in the field type def XML files
         Object value = get(name);
-        if (value instanceof Double) {
-            return BigDecimal.valueOf(((Double) value).doubleValue());
-        } else {
-            return (BigDecimal) value;
+        if (value != null) {
+            try {
+                Double numValue = (Double) value;
+                return new BigDecimal(numValue.doubleValue());
+            } catch (ClassCastException e) {
+            }
         }
+        return (BigDecimal) value;
     }
 
     @SuppressWarnings("deprecation")