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

io.rapidpro.flows.definition.tests.numeric.LessThanTest Maven / Gradle / Ivy

There is a newer version: 11.5
Show newest version
package io.rapidpro.flows.definition.tests.numeric;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.rapidpro.flows.definition.Flow;
import io.rapidpro.flows.definition.FlowParseException;
import io.rapidpro.flows.definition.tests.Test;
import io.rapidpro.flows.utils.JsonUtils;

import java.math.BigDecimal;

/**
 * Test which returns whether input is numerically less than a value
 */
public class LessThanTest extends NumericComparisonTest {

    public static final String TYPE = "lt";

    public LessThanTest(String test) {
        super(test);
    }

    /**
     * @see Test#fromJson(JsonElement, Flow.DeserializationContext)
     */
    public static LessThanTest fromJson(JsonElement elm, Flow.DeserializationContext context) throws FlowParseException {
        JsonObject obj = elm.getAsJsonObject();
        return new LessThanTest(obj.get("test").getAsString());
    }

    @Override
    public JsonElement toJson() {
        return JsonUtils.object("type", TYPE, "test", m_test);
    }

    /**
     * @see NumericComparisonTest#doComparison(BigDecimal, BigDecimal)
     */
    @Override
    protected boolean doComparison(BigDecimal input, BigDecimal test) {
        return input.compareTo(test) < 0;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy