com.hubspot.jinjava.lib.exptest.IsIterableExpTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jinjava Show documentation
Show all versions of jinjava Show documentation
Jinja templating engine implemented in Java
package com.hubspot.jinjava.lib.exptest;
import com.hubspot.jinjava.doc.annotations.JinjavaDoc;
import com.hubspot.jinjava.doc.annotations.JinjavaSnippet;
import com.hubspot.jinjava.interpret.JinjavaInterpreter;
@JinjavaDoc(
value = "Return true if the object is iterable (sequence, dict, etc)",
snippets = {
@JinjavaSnippet(
code = "{% if variable is iterable %}\n" +
" \n" +
"{% endif %}")
})
public class IsIterableExpTest implements ExpTest {
@Override
public String getName() {
return "iterable";
}
@Override
public boolean evaluate(Object var, JinjavaInterpreter interpreter, Object... args) {
return var != null && (var.getClass().isArray() || Iterable.class.isAssignableFrom(var.getClass()));
}
}