You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2014/09/08 20:34:40 UTC
svn commit: r1623456 -
/tomcat/trunk/java/org/apache/el/lang/ELArithmetic.java
Author: markt
Date: Mon Sep 8 18:34:39 2014
New Revision: 1623456
URL: http://svn.apache.org/r1623456
Log:
Extract common code into a new method to reduce duplication identified by Simian.
Modified:
tomcat/trunk/java/org/apache/el/lang/ELArithmetic.java
Modified: tomcat/trunk/java/org/apache/el/lang/ELArithmetic.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/lang/ELArithmetic.java?rev=1623456&r1=1623455&r2=1623456&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/lang/ELArithmetic.java (original)
+++ tomcat/trunk/java/org/apache/el/lang/ELArithmetic.java Mon Sep 8 18:34:39 2014
@@ -249,23 +249,11 @@ public abstract class ELArithmetic {
private static final Long ZERO = Long.valueOf(0);
public static final Number add(final Object obj0, final Object obj1) {
- if (obj0 == null && obj1 == null) {
+ final ELArithmetic delegate = findDelegate(obj0, obj1);
+ if (delegate == null) {
return Long.valueOf(0);
}
- final ELArithmetic delegate;
- if (BIGDECIMAL.matches(obj0, obj1))
- delegate = BIGDECIMAL;
- else if (DOUBLE.matches(obj0, obj1)) {
- if (BIGINTEGER.matches(obj0, obj1))
- delegate = BIGDECIMAL;
- else
- delegate = DOUBLE;
- } else if (BIGINTEGER.matches(obj0, obj1))
- delegate = BIGINTEGER;
- else
- delegate = LONG;
-
Number num0 = delegate.coerce(obj0);
Number num1 = delegate.coerce(obj1);
@@ -294,23 +282,11 @@ public abstract class ELArithmetic {
}
public static final Number subtract(final Object obj0, final Object obj1) {
- if (obj0 == null && obj1 == null) {
+ final ELArithmetic delegate = findDelegate(obj0, obj1);
+ if (delegate == null) {
return Long.valueOf(0);
}
- final ELArithmetic delegate;
- if (BIGDECIMAL.matches(obj0, obj1))
- delegate = BIGDECIMAL;
- else if (DOUBLE.matches(obj0, obj1)) {
- if (BIGINTEGER.matches(obj0, obj1))
- delegate = BIGDECIMAL;
- else
- delegate = DOUBLE;
- } else if (BIGINTEGER.matches(obj0, obj1))
- delegate = BIGINTEGER;
- else
- delegate = LONG;
-
Number num0 = delegate.coerce(obj0);
Number num1 = delegate.coerce(obj1);
@@ -337,29 +313,37 @@ public abstract class ELArithmetic {
}
public static final Number multiply(final Object obj0, final Object obj1) {
- if (obj0 == null && obj1 == null) {
+ final ELArithmetic delegate = findDelegate(obj0, obj1);
+ if (delegate == null) {
return Long.valueOf(0);
}
- final ELArithmetic delegate;
- if (BIGDECIMAL.matches(obj0, obj1))
- delegate = BIGDECIMAL;
- else if (DOUBLE.matches(obj0, obj1)) {
- if (BIGINTEGER.matches(obj0, obj1))
- delegate = BIGDECIMAL;
- else
- delegate = DOUBLE;
- } else if (BIGINTEGER.matches(obj0, obj1))
- delegate = BIGINTEGER;
- else
- delegate = LONG;
-
Number num0 = delegate.coerce(obj0);
Number num1 = delegate.coerce(obj1);
return delegate.multiply(num0, num1);
}
+ private static ELArithmetic findDelegate(final Object obj0, final Object obj1) {
+ if (obj0 == null && obj1 == null) {
+ return null;
+ }
+
+ if (BIGDECIMAL.matches(obj0, obj1)) {
+ return BIGDECIMAL;
+ } else if (DOUBLE.matches(obj0, obj1)) {
+ if (BIGINTEGER.matches(obj0, obj1)) {
+ return BIGDECIMAL;
+ } else {
+ return DOUBLE;
+ }
+ } else if (BIGINTEGER.matches(obj0, obj1)) {
+ return BIGINTEGER;
+ } else {
+ return LONG;
+ }
+ }
+
public static final boolean isNumber(final Object obj) {
return (obj != null && isNumberType(obj.getClass()));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org