All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hubspot.jinjava.lib.exptest.IsOddExpTest Maven / Gradle / Ivy

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;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy