Package com.googlecode.aviator.runtime.type

Examples of com.googlecode.aviator.runtime.type.AviatorObject


    @Test(expected = IllegalArgumentException.class)
    public void testPredicate_IllegalArguments() {
        SeqPredicateFunction fun = new SeqPredicateFunction("le", OperatorType.LE, new AviatorRuntimeJavaType("hello"));

        AviatorObject args[] = new AviatorObject[2];
        args[0] = new AviatorRuntimeJavaType("hello");
        AviatorObject result = fun.call(null, args);

    }
View Full Code Here


    @Test(expected = ExpressionRuntimeException.class)
    public void testPredicate_IllegalOperator() {
        SeqPredicateFunction fun =
                new SeqPredicateFunction("and", OperatorType.AND, new AviatorRuntimeJavaType("hello"));

        AviatorObject args[] = new AviatorObject[1];
        args[0] = new AviatorRuntimeJavaType("hello");
        AviatorObject result = fun.call(null, args);
    }
View Full Code Here

        assertNotNull(predicateName);
        assertEquals(1, env.size());
        AviatorFunction predicate = (AviatorFunction) env.get(predicateName.getName());
        assertNotNull(predicate);
        AviatorObject result = predicate.call(null, args);
        // equals self
        assertTrue(result.booleanValue(null));

    }
View Full Code Here

        assertEquals(1, env.size());
        AviatorFunction predicate = (AviatorFunction) env.get(predicateName.getName());
        assertNotNull(predicate);
        AviatorObject[] args = new AviatorObject[1];
        args[0] = new AviatorRuntimeJavaType("hello");
        AviatorObject result = predicate.call(null, args);
        // equals self
        assertTrue(result.booleanValue(null));

        args[0] = new AviatorRuntimeJavaType("he11o");
        result = predicate.call(null, args);
        // equals self
        assertFalse(result.booleanValue(null));

    }
View Full Code Here

    public AviatorObject call(Map<String, Object> env, AviatorObject... args) {
        if (args.length != this.opType.getOperandCount()) {
            throw new IllegalArgumentException(getName() + " has only " + opType.getOperandCount() + " arguments");
        }
        AviatorObject left = args[0];
        switch (opType) {
        case ADD:
            AviatorObject right = args[1];
            return left.add(right, env);
        case SUB:
            right = args[1];
            return left.sub(right, env);
        case MULT:
View Full Code Here

                // set argument token to null
                tokenList.set(j, null);

            }
            // execute it now
            AviatorObject result = operatorType.eval(args);
            // set result as token to tokenList for next executing
            tokenList.set(operatorIndex, getTokenFromOperand(result));
            return 1;
        }
        return 0;
View Full Code Here

        }
    }


    private AviatorObject getAviatorObjectFromToken(Token<?> lookhead) {
        AviatorObject result = null;
        switch (lookhead.getType()) {
        case Number:
            // load numbers
            NumberToken numberToken = (NumberToken) lookhead;
            if (numberToken.getNumber() instanceof Double) {
View Full Code Here

        return result;
    }


    public static Object getJavaObject(int index, AviatorObject[] args, Map<String, Object> env) {
        final AviatorObject arg = args[index];
        if (!(arg instanceof AviatorJavaType)) {
            throw new ExpressionRuntimeException(arg.desc(env) + " is not a javaType");
        }
        return env.get(((AviatorJavaType) arg).getName());
    }
View Full Code Here

        return env.get(((AviatorJavaType) arg).getName());
    }


    public static AviatorFunction getFunction(int index, AviatorObject[] args, Map<String, Object> env, int arity) {
        final AviatorObject arg = args[index];
        if (!(arg instanceof AviatorJavaType)) {
            throw new ExpressionRuntimeException(arg.desc(env) + " is not a function");
        }
        // special processing for "-" operator
        String name = ((AviatorJavaType) arg).getName();
        if (name.equals("-")) {
            if (arity == 2) {
View Full Code Here

            cachedFunction = (AviatorFunction) env.get(this.methodName);
        }
        if (cachedFunction == null) {
            throw new ExpressionRuntimeException("Could not find method named " + methodName);
        }
        final AviatorObject result = cachedFunction.call(env, list.toArray(new AviatorObject[list.size()]));
        return result == null ? AviatorNil.NIL : result;
    }
View Full Code Here

TOP

Related Classes of com.googlecode.aviator.runtime.type.AviatorObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.