Search in sources :

Example 6 with FieldValue

use of org.activityinfo.model.type.FieldValue in project activityinfo by bedatadriven.

the class ComparisonOperator method apply.

@Override
public FieldValue apply(List<FieldValue> arguments) {
    FieldValue a = arguments.get(0);
    FieldValue b = arguments.get(1);
    return BooleanFieldValue.valueOf(apply(a, b));
}
Also used : FieldValue(org.activityinfo.model.type.FieldValue) BooleanFieldValue(org.activityinfo.model.type.primitive.BooleanFieldValue)

Example 7 with FieldValue

use of org.activityinfo.model.type.FieldValue in project activityinfo by bedatadriven.

the class IfFunction method apply.

@Override
public FieldValue apply(List<FieldValue> arguments) {
    checkArity(arguments, 3);
    BooleanFieldValue condition = toBoolean(arguments.get(0));
    FieldValue ifTrue = arguments.get(1);
    FieldValue ifFalse = arguments.get(2);
    if (condition == BooleanFieldValue.TRUE) {
        return ifTrue;
    } else {
        return ifFalse;
    }
}
Also used : FieldValue(org.activityinfo.model.type.FieldValue) BooleanFieldValue(org.activityinfo.model.type.primitive.BooleanFieldValue) BooleanFieldValue(org.activityinfo.model.type.primitive.BooleanFieldValue)

Example 8 with FieldValue

use of org.activityinfo.model.type.FieldValue in project activityinfo by bedatadriven.

the class CeilingFunctionTest method test.

@Test
public void test() {
    assertThat(CeilingFunction.INSTANCE.apply(1.6), Matchers.equalTo(2.0));
    assertThat(CeilingFunction.INSTANCE.apply(1.5), Matchers.equalTo(2.0));
    assertThat(CeilingFunction.INSTANCE.apply(1.4), Matchers.equalTo(2.0));
    assertThat(CeilingFunction.INSTANCE.apply(-1.6), Matchers.equalTo(-1.0));
    assertThat(CeilingFunction.INSTANCE.apply(-1.5), Matchers.equalTo(-1.0));
    assertThat(CeilingFunction.INSTANCE.apply(-1.4), Matchers.equalTo(-1.0));
    assertThat(CeilingFunction.INSTANCE.apply(Collections.<FieldValue>singletonList(new Quantity(1.5))), Matchers.<FieldValue>equalTo(new Quantity(2.0)));
    assertThat(CeilingFunction.INSTANCE.apply(Collections.<FieldValue>singletonList(new Quantity(-1.5))), Matchers.<FieldValue>equalTo(new Quantity(-1.0)));
}
Also used : Quantity(org.activityinfo.model.type.number.Quantity) FieldValue(org.activityinfo.model.type.FieldValue) Test(org.junit.Test)

Example 9 with FieldValue

use of org.activityinfo.model.type.FieldValue in project activityinfo by bedatadriven.

the class FloorFunctionTest method test.

@Test
public void test() {
    assertThat(FloorFunction.INSTANCE.apply(1.6), Matchers.equalTo(1.0));
    assertThat(FloorFunction.INSTANCE.apply(1.5), Matchers.equalTo(1.0));
    assertThat(FloorFunction.INSTANCE.apply(1.4), Matchers.equalTo(1.0));
    assertThat(FloorFunction.INSTANCE.apply(-1.6), Matchers.equalTo(-2.0));
    assertThat(FloorFunction.INSTANCE.apply(-1.5), Matchers.equalTo(-2.0));
    assertThat(FloorFunction.INSTANCE.apply(-1.4), Matchers.equalTo(-2.0));
    assertThat(FloorFunction.INSTANCE.apply(Collections.<FieldValue>singletonList(new Quantity(1.5))), Matchers.<FieldValue>equalTo(new Quantity(1.0)));
    assertThat(FloorFunction.INSTANCE.apply(Collections.<FieldValue>singletonList(new Quantity(-1.5))), Matchers.<FieldValue>equalTo(new Quantity(-2.0)));
}
Also used : Quantity(org.activityinfo.model.type.number.Quantity) FieldValue(org.activityinfo.model.type.FieldValue) Test(org.junit.Test)

Example 10 with FieldValue

use of org.activityinfo.model.type.FieldValue in project activityinfo by bedatadriven.

the class YearFracFunctionTest method evaluation.

@Test
public void evaluation() {
    LocalDate x = new LocalDate(2016, 1, 1);
    LocalDate y = new LocalDate(2017, 1, 1);
    Quantity z = (Quantity) YearFracFunction.INSTANCE.apply(Arrays.<FieldValue>asList(x, y));
    assertThat(z, equalTo(new Quantity(1.0)));
}
Also used : Quantity(org.activityinfo.model.type.number.Quantity) FieldValue(org.activityinfo.model.type.FieldValue) LocalDate(org.activityinfo.model.type.time.LocalDate) Test(org.junit.Test)

Aggregations

FieldValue (org.activityinfo.model.type.FieldValue)49 ResourceId (org.activityinfo.model.resource.ResourceId)16 FormField (org.activityinfo.model.form.FormField)13 Test (org.junit.Test)12 FormInstance (org.activityinfo.model.form.FormInstance)10 Quantity (org.activityinfo.model.type.number.Quantity)9 JsonValue (org.activityinfo.json.JsonValue)8 FormClass (org.activityinfo.model.form.FormClass)8 ReferenceValue (org.activityinfo.model.type.ReferenceValue)7 RecordRef (org.activityinfo.model.type.RecordRef)6 ResultSet (java.sql.ResultSet)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 SerialNumberType (org.activityinfo.model.type.SerialNumberType)5 BooleanFieldValue (org.activityinfo.model.type.primitive.BooleanFieldValue)5 SerialNumber (org.activityinfo.model.type.SerialNumber)4 GeoPoint (org.activityinfo.model.type.geo.GeoPoint)4 LocalDate (org.activityinfo.model.type.time.LocalDate)4 JsonMappingException (org.activityinfo.json.JsonMappingException)3 FormulaNode (org.activityinfo.model.formula.FormulaNode)3