treat empty list as null

This commit is contained in:
Reinhard Pointner 2017-03-27 18:07:41 +08:00
parent 52ef8e5b5b
commit fb81a895b8
2 changed files with 24 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import static net.filebot.util.ExceptionUtilities.*;
import java.lang.reflect.Method;
import java.util.AbstractMap;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@ -42,10 +43,21 @@ public class ExpressionBindings extends AbstractMap<String, Object> implements B
}
protected boolean isUndefined(Object value) {
if (value instanceof CharSequence) {
return ((CharSequence) value).length() <= 0;
if (value == null) {
return true;
}
return value == null;
// treat empty string as null
if (value instanceof CharSequence && value.toString().isEmpty()) {
return true;
}
// treat empty list as null
if (value instanceof Collection && ((Collection) value).isEmpty()) {
return true;
}
return false;
}
public Object getBindingBean() {

View File

@ -7,6 +7,7 @@ import static net.filebot.util.RegularExpressions.*;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -38,9 +39,17 @@ public class ExpressionFormatFunctions {
return null;
}
}
// treat empty string as null
if (object instanceof CharSequence && object.toString().isEmpty()) {
return null;
}
// treat empty list as null
if (object instanceof Collection && ((Collection) object).isEmpty()) {
return null;
}
return object;
}