Search in sources :

Example 66 with FunctionInterface

use of com.dexels.navajo.expression.api.FunctionInterface in project navajo by Dexels.

the class TestCompiledLongExpression method testSubtractWithLongs.

@Test
public void testSubtractWithLongs() {
    FunctionInterface helperFunction = new GiveLongTestFunction();
    FunctionDefinition fd = new FunctionDefinition(helperFunction.getClass().getName(), "description", "input", "result");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("ToLong", fd);
    Operand result;
    result = Expression.evaluate("ToLong(2) - ToLong(1)", null, null, null);
    Assert.assertEquals(1L, (long) result.value);
    result = Expression.evaluate("2 - ToLong(1)", null, null, null);
    Assert.assertEquals(1L, (long) result.value);
    result = Expression.evaluate("ToLong(2) - 1", null, null, null);
    Assert.assertEquals(1L, (long) result.value);
    result = Expression.evaluate("2.0 - ToLong(1)", null, null, null);
    Assert.assertEquals(1.0, (double) result.value, 0.000001);
    result = Expression.evaluate("ToLong(2) - 1.0", null, null, null);
    Assert.assertEquals(1.0, (double) result.value, 0.000001);
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) Operand(com.dexels.navajo.document.Operand) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) GiveLongTestFunction(com.dexels.navajo.expression.compiled.GiveLongTestFunction) Test(org.junit.Test)

Example 67 with FunctionInterface

use of com.dexels.navajo.expression.api.FunctionInterface in project navajo by Dexels.

the class TestCompiledPercentageExpression method setup.

@Before
public void setup() {
    FunctionInterface giveLongFunction = new GiveLongTestFunction();
    FunctionDefinition fd = new FunctionDefinition(giveLongFunction.getClass().getName(), "description", "input", "result");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("ToLong", fd);
    FunctionInterface givePercentageFunction = new GivePercentageTestFunction();
    fd = new FunctionDefinition(givePercentageFunction.getClass().getName(), "description", "input", "result");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("ToPercentage", fd);
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) GiveLongTestFunction(com.dexels.navajo.expression.compiled.GiveLongTestFunction) GivePercentageTestFunction(com.dexels.navajo.expression.compiled.GivePercentageTestFunction) Before(org.junit.Before)

Example 68 with FunctionInterface

use of com.dexels.navajo.expression.api.FunctionInterface in project navajo by Dexels.

the class FunctionListCommand method functions.

public void functions(CommandSession session, String filter) {
    String serviceFilter = null;
    if (filter != null) {
        serviceFilter = "(functionName=" + filter + ")";
    }
    session.getConsole().println("filter: " + filter);
    try {
        Collection<ServiceReference<FunctionInterface>> result = bundleContext.getServiceReferences(FunctionInterface.class, serviceFilter);
        for (ServiceReference<FunctionInterface> serviceReference : result) {
            String functionName = (String) serviceReference.getProperty("functionName");
            FunctionDefinition fd = (FunctionDefinition) serviceReference.getProperty("functionDefinition");
            session.getConsole().println("" + functionName);
            session.getConsole().println("\t" + fd.getDescription());
        // }
        }
    } catch (InvalidSyntaxException e) {
        e.printStackTrace(session.getConsole());
    }
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ServiceReference(org.osgi.framework.ServiceReference)

Example 69 with FunctionInterface

use of com.dexels.navajo.expression.api.FunctionInterface in project navajo by Dexels.

the class StandardFunctionsTest method testOffsetDate.

@Test
public void testOffsetDate() {
    FunctionInterface fi = fff.getInstance(cl, "OffsetDate");
    fi.reset();
    fi.insertDateOperand(new Date());
    fi.insertIntegerOperand(10);
    fi.insertIntegerOperand(6);
    fi.insertIntegerOperand(17);
    fi.insertIntegerOperand(12);
    fi.insertIntegerOperand(0);
    fi.insertIntegerOperand(0);
    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(Date.class, o.getClass());
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) Date(java.util.Date) Test(org.junit.Test)

Example 70 with FunctionInterface

use of com.dexels.navajo.expression.api.FunctionInterface in project navajo by Dexels.

the class StandardFunctionsTest method testToSecureImage.

@Test
public void testToSecureImage() {
    FunctionInterface fi = fff.getInstance(cl, "ToSecureImage");
    fi.reset();
    fi.insertStringOperand("SECURE");
    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(Binary.class, o.getClass());
    fi.reset();
    fi.insertOperand(Operand.NULL);
    o = fi.evaluateWithTypeChecking();
    assertNull(o);
    System.err.println(System.currentTimeMillis());
    long l = (Long.parseLong("1234567890000") - System.currentTimeMillis());
    Calendar c = Calendar.getInstance();
    c.add(Calendar.MILLISECOND, (int) l);
    System.err.println(SimpleDateFormat.getInstance().format(c.getTime()));
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) Calendar(java.util.Calendar) Test(org.junit.Test)

Aggregations

FunctionInterface (com.dexels.navajo.expression.api.FunctionInterface)161 Test (org.junit.Test)153 Navajo (com.dexels.navajo.document.Navajo)26 FunctionDefinition (com.dexels.navajo.expression.api.FunctionDefinition)20 ArrayList (java.util.ArrayList)16 Date (java.util.Date)16 Operand (com.dexels.navajo.document.Operand)10 GiveLongTestFunction (com.dexels.navajo.expression.compiled.GiveLongTestFunction)10 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)7 CapString (com.dexels.navajo.functions.CapString)7 StringReader (java.io.StringReader)5 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)4 AddTestFunction (com.dexels.navajo.expression.compiled.AddTestFunction)4 Binary (com.dexels.navajo.document.types.Binary)3 CheckInteger (com.dexels.navajo.functions.CheckInteger)3 SimpleDateFormat (java.text.SimpleDateFormat)3 List (java.util.List)3 Message (com.dexels.navajo.document.Message)2 Property (com.dexels.navajo.document.Property)2 ClockTime (com.dexels.navajo.document.types.ClockTime)2