Examples of AviatorRuntimeJavaType


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

    public AviatorObject call(Map<String, Object> env, AviatorObject... args) {
        if (args.length > 0) {
            throw new IllegalArgumentException("sysdate()");
        }
        return new AviatorRuntimeJavaType(new Date());
    }
View Full Code Here

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

            catch (Throwable t) {
                // ignore
                result = new ArrayList();
            }
            for (Object obj : (Collection<?>) first) {
                if (fun.call(env, new AviatorRuntimeJavaType(obj)).booleanValue(env)) {
                    result.add(obj);
                }
            }
            return new AviatorRuntimeJavaType(result);
        }
        else if (clazz.isArray()) {
            Object[] seq = (Object[]) first;
            List result = new ArrayList();
            for (Object obj : seq) {
                if (fun.call(env, new AviatorRuntimeJavaType(obj)).booleanValue(env)) {
                    result.add(obj);
                }
            }
            return new AviatorRuntimeJavaType(result.toArray());
        }
        else {
            throw new IllegalArgumentException(args[0].desc(env) + " is not a seq");
        }
View Full Code Here

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

        AviatorObject result = args[2];
        Class<?> clazz = first.getClass();

        if (Collection.class.isAssignableFrom(clazz)) {
            for (Object obj : (Collection<?>) first) {
                result = fun.call(env, result, new AviatorRuntimeJavaType(obj));
            }
        }
        else if (clazz.isArray()) {
            Object[] seq = (Object[]) first;
            for (Object obj : seq) {
                result = fun.call(env, result, new AviatorRuntimeJavaType(obj));
            }
        }
        else {
            throw new IllegalArgumentException(args[0].desc(env) + " is not a seq");
        }
View Full Code Here

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

        if (List.class.isAssignableFrom(clazz)) {
            List<?> list = (List<?>) first;
            Object[] a = list.toArray();
            Arrays.sort(a);
            return new AviatorRuntimeJavaType(Arrays.asList(a));
        }
        else if (clazz.isArray()) {
            Object[] array = (Object[]) first;
            Object[] dup = (Object[]) Array.newInstance(array.getClass().getComponentType(), array.length);
            System.arraycopy(array, 0, dup, 0, dup.length);
            Arrays.sort(dup);
            return new AviatorRuntimeJavaType(dup);
        }
        else {
            throw new IllegalArgumentException(args[0].desc(env) + " is not a seq");
        }
    }
View Full Code Here

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

        boolean contains = false;
        if (Collection.class.isAssignableFrom(clazz)) {
            Collection<?> seq = (Collection<?>) first;
            try {
                for (Object obj : seq) {
                    if (new AviatorRuntimeJavaType(obj).compare(second, env) == 0) {
                        contains = true;
                        break;
                    }
                }
            }
            catch (Exception e) {
                return AviatorBoolean.FALSE;
            }
        }
        else if (clazz.isArray()) {
            Object[] seq = (Object[]) first;
            try {
                for (Object obj : seq) {
                    if (new AviatorRuntimeJavaType(obj).compare(second, env) == 0) {
                        contains = true;
                        break;
                    }
                }
            }
View Full Code Here

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

            catch (Throwable t) {
                // ignore
                result = new ArrayList();
            }
            for (Object obj : (Collection<?>) first) {
                result.add(fun.call(env, new AviatorRuntimeJavaType(obj)).getValue(env));
            }
            return new AviatorRuntimeJavaType(result);
        }
        else if (clazz.isArray()) {
            Object[] seq = (Object[]) first;
            Object result = Array.newInstance(Object.class, seq.length);
            int index = 0;
            for (Object obj : seq) {
                Array.set(result, index++, fun.call(env, new AviatorRuntimeJavaType(obj)).getValue(env));
            }
            return new AviatorRuntimeJavaType(result);
        }
        else {
            throw new IllegalArgumentException(args[0].desc(env) + " is not a seq");
        }
View Full Code Here

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

public class SeqCountFunctionUnitTest {

    @Test
    public void testCount_Array() {
        AviatorObject[] args = new AviatorObject[1];
        args[0] = new AviatorRuntimeJavaType(new String[10]);
        SeqCountFunction fun = new SeqCountFunction();
        AviatorObject result = fun.call(null, args);
        assertEquals(10, result.getValue(null));
    }
View Full Code Here

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


    @Test
    public void testCount_EmptyArray() {
        AviatorObject[] args = new AviatorObject[1];
        args[0] = new AviatorRuntimeJavaType(new String[0]);
        SeqCountFunction fun = new SeqCountFunction();
        AviatorObject result = fun.call(null, args);
        assertEquals(0, result.getValue(null));
    }
View Full Code Here

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

    public void testCount_Collection() {
        AviatorObject[] args = new AviatorObject[1];
        final HashSet<Integer> set = new HashSet<Integer>();
        set.add(1);
        set.add(2);
        args[0] = new AviatorRuntimeJavaType(set);
        SeqCountFunction fun = new SeqCountFunction();
        AviatorObject result = fun.call(null, args);
        assertEquals(2, result.getValue(null));
    }
View Full Code Here

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

    @Test(expected = IllegalArgumentException.class)
    public void testCount_String() {
        AviatorObject[] args = new AviatorObject[1];

        args[0] = new AviatorRuntimeJavaType("hello");
        SeqCountFunction fun = new SeqCountFunction();
        AviatorObject result = fun.call(null, args);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.