in src/main/java/org/apache/sling/scripting/sightly/impl/engine/runtime/SlingRuntimeObjectModel.java [46:94]
public boolean toBoolean(Object object) {
if (legacyToBoolean) {
if (object == null) {
return false;
}
if (object instanceof Number) {
Number number = (Number) object;
return number.doubleValue() != 0.0;
}
String s = object.toString();
if (s != null) {
s = s.trim();
}
if (EMPTY_STRING.equals(s)) {
return false;
} else if ("true".equalsIgnoreCase(s) || "false".equalsIgnoreCase(s)) {
return Boolean.parseBoolean(s);
}
if (object instanceof Collection) {
return !((Collection) object).isEmpty();
}
if (object instanceof Map) {
return !((Map) object).isEmpty();
}
if (object instanceof Iterable<?>) {
return ((Iterable<?>) object).iterator().hasNext();
}
if (object instanceof Iterator<?>) {
return ((Iterator<?>) object).hasNext();
}
if (object instanceof Optional) {
return toBoolean(((Optional) object).orElse(false));
}
if (object.getClass().isArray()) {
return Array.getLength(object) > 0;
}
return true;
}
return super.toBoolean(object);
}