com.hubspot.jinjava.lib.exptest.IsOddExpTest 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
The newest version!
package com.hubspot.jinjava.lib.exptest;
import com.hubspot.jinjava.doc.annotations.JinjavaDoc;
import com.hubspot.jinjava.doc.annotations.JinjavaParam;
import com.hubspot.jinjava.doc.annotations.JinjavaSnippet;
import com.hubspot.jinjava.interpret.JinjavaInterpreter;
@JinjavaDoc(
value = "Return true if a number is an odd number",
input = @JinjavaParam(value = "num", type = "number", required = true),
snippets = {
@JinjavaSnippet(
code = "{% if variable is odd %}\n" +
" \n" +
"{% else %}\n" +
" \n" +
"{% endif %}"
),
}
)
public class IsOddExpTest implements ExpTest {
@Override
public String getName() {
return "odd";
}
@Override
public boolean evaluate(Object var, JinjavaInterpreter interpreter, Object... args) {
if (var == null || !Number.class.isAssignableFrom(var.getClass())) {
return false;
}
return ((Number) var).intValue() % 2 != 0;
}
}