Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.lib / org.gvsig.expressionevaluator.lib.impl / src / main / java / org / gvsig / expressionevaluator / impl / function / programming / MapFunction.java @ 45025

History | View | Annotate | Download (1.39 KB)

1 44138 jjdelcerro
package org.gvsig.expressionevaluator.impl.function.programming;
2 43512 jjdelcerro
3 45025 jjdelcerro
import java.util.ArrayList;
4
import java.util.List;
5 43512 jjdelcerro
import org.apache.commons.lang3.Range;
6 43939 jjdelcerro
import org.gvsig.expressionevaluator.Function;
7 43521 jjdelcerro
import org.gvsig.expressionevaluator.Interpreter;
8 43512 jjdelcerro
import org.gvsig.expressionevaluator.spi.AbstractFunction;
9 45025 jjdelcerro
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_MAP;
10
import org.gvsig.tools.util.GetItemWithSize;
11
import org.gvsig.tools.util.GetItemWithSize64;
12 43512 jjdelcerro
13 45025 jjdelcerro
public class MapFunction extends AbstractFunction {
14 44138 jjdelcerro
15 45025 jjdelcerro
    public MapFunction() {
16 44138 jjdelcerro
        super(Function.GROUP_PROGRAMMING,
17 45025 jjdelcerro
                FUNCTION_MAP,
18
                Range.is(2),
19 44098 jjdelcerro
                null,
20 45025 jjdelcerro
                FUNCTION_MAP+"({{function}}, list)",
21 44138 jjdelcerro
                null,
22 45025 jjdelcerro
                "List",
23 44098 jjdelcerro
                false
24 43939 jjdelcerro
        );
25 43512 jjdelcerro
    }
26
27
    @Override
28 44138 jjdelcerro
    public boolean allowConstantFolding() {
29
        return false;
30 43939 jjdelcerro
    }
31 44138 jjdelcerro
32 43939 jjdelcerro
    @Override
33 43521 jjdelcerro
    public Object call(Interpreter interpreter, Object[] args) throws Exception {
34 45025 jjdelcerro
        GetItemWithSize64 list_in = this.getList(args, 1);
35
        List<Object> list_out = new ArrayList<>();
36
        Function func = (Function) this.getObject(args, 0);
37
        for (long i = 0; i < list_in.size64(); i++) {
38
            Object obj = list_in.get64(i);
39
            Object v = func.call(interpreter, new Object[] { obj });
40
            list_out.add(v);
41 45011 jjdelcerro
        }
42 45025 jjdelcerro
        return list_out;
43 45011 jjdelcerro
    }
44
45 43512 jjdelcerro
}