This is an automated email from the ASF dual-hosted git repository.
henrib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git
The following commit(s) were added to refs/heads/master by this push:
new 7042254 JEXL-298: tidy empty/isEmpty logic
7042254 is described below
commit 7042254316bf99ac4eabf8fc74522bf93a3a797b
Author: Henri Biestro <[email protected]>
AuthorDate: Wed Jun 5 22:10:39 2019 +0200
JEXL-298: tidy empty/isEmpty logic
---
.../org/apache/commons/jexl3/JexlArithmetic.java | 40 ++++++++++++----------
1 file changed, 21 insertions(+), 19 deletions(-)
diff --git a/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
b/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
index 094f2d7..ca25585 100644
--- a/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
+++ b/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
@@ -975,7 +975,7 @@ public class JexlArithmetic {
*/
public Boolean empty(Object object) {
Boolean e = isEmpty(object);
- return e == null ? Boolean.TRUE : e;
+ return e == null ? Boolean.FALSE : e;
}
/**
@@ -985,25 +985,27 @@ public class JexlArithmetic {
* @return the boolean or null if there is no arithmetic solution
*/
public Boolean isEmpty(Object object) {
- if (object != null) {
- if (object instanceof Number) {
- double d = ((Number) object).doubleValue();
- return Double.isNaN(d) || d == 0.d ? Boolean.TRUE :
Boolean.FALSE;
- }
- if (object instanceof CharSequence) {
- return ((CharSequence) object).length() == 0 ? Boolean.TRUE :
Boolean.FALSE;
- }
- if (object.getClass().isArray()) {
- return Array.getLength(object) == 0 ? Boolean.TRUE :
Boolean.FALSE;
- }
- if (object instanceof Collection<?>) {
- return ((Collection<?>) object).isEmpty() ? Boolean.TRUE :
Boolean.FALSE;
- }
- // Map isn't a collection
- if (object instanceof Map<?, ?>) {
- return ((Map<?, ?>) object).isEmpty() ? Boolean.TRUE :
Boolean.FALSE;
- }
+ if (object == null) {
+ return Boolean.TRUE;
+ }
+ if (object instanceof Number) {
+ double d = ((Number) object).doubleValue();
+ return Double.isNaN(d) || d == 0.d ? Boolean.TRUE : Boolean.FALSE;
+ }
+ if (object instanceof CharSequence) {
+ return ((CharSequence) object).length() == 0 ? Boolean.TRUE :
Boolean.FALSE;
+ }
+ if (object.getClass().isArray()) {
+ return Array.getLength(object) == 0 ? Boolean.TRUE : Boolean.FALSE;
+ }
+ if (object instanceof Collection<?>) {
+ return ((Collection<?>) object).isEmpty() ? Boolean.TRUE :
Boolean.FALSE;
+ }
+ // Map isn't a collection
+ if (object instanceof Map<?, ?>) {
+ return ((Map<?, ?>) object).isEmpty() ? Boolean.TRUE :
Boolean.FALSE;
}
+ // we can not determine for sure...
return null;
}