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 / DefaultSymbolTable.java @ 44533

History | View | Annotate | Download (2.58 KB)

1
package org.gvsig.expressionevaluator.impl;
2

    
3
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable;
4
import java.util.Collection;
5
import java.util.HashMap;
6
import org.apache.commons.lang3.StringUtils;
7
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
8
import org.gvsig.expressionevaluator.Function;
9
import org.gvsig.expressionevaluator.MutableSymbolTable;
10

    
11
/**
12
 *
13
 * @author jjdelcerro
14
 */
15
public class DefaultSymbolTable 
16
        extends AbstractSymbolTable
17
        implements MutableSymbolTable 
18
    {
19

    
20

    
21
    public DefaultSymbolTable() {
22
        super();
23
        this.vars = new HashMap<>();
24
        this.functions = new HashMap<>();
25
//        this.scripts = new ArrayList<>();
26
        this.init();
27
    }
28
    
29
    private void init() {
30
        DefaultExpressionEvaluatorManager manager = (DefaultExpressionEvaluatorManager) ExpressionEvaluatorLocator.getManager();
31
        manager.populateSymbolTable(this);
32
    }
33
    
34
    @Override
35
    public void setVar(String name, Object value) {
36
        if( StringUtils.isEmpty(name) ) {
37
            throw new IllegalArgumentException("name can't be null");
38
        }
39
        this.vars.put(name.toUpperCase(), value);
40
    }
41

    
42
    @Override
43
    public void addFunction(Function function) {
44
        super.addFunction(function);
45
    }
46

    
47
    @Override
48
    public void addFunctions(Collection<Function> functions) {
49
        for (Function function : functions) {
50
            this.addFunction(function);
51
        }
52
    }
53

    
54
    @Override
55
    public void removeVar(String name) {
56
        if( StringUtils.isEmpty(name) ) {
57
            throw new IllegalArgumentException("name can't be null");
58
        }
59
        this.vars.remove(name.toUpperCase());
60
    }
61

    
62
    @Override
63
    public void removeFunction(String name) {
64
        if( StringUtils.isEmpty(name) ) {
65
            throw new IllegalArgumentException("name can't be null");
66
        }
67
        this.functions.remove(name.toUpperCase());
68
    }
69

    
70
//    @Override
71
//    public void addScript(Script script) {
72
//        if( script == null ) {
73
//            throw new IllegalArgumentException("script can't be null");
74
//        }
75
//        if (this.scripts.contains(script)) {
76
//            return;
77
//        }
78
//        this.scripts.add(script);
79
//    }
80
//
81
//    @Override
82
//    public void removeScript(Script script) {
83
//        if( script == null ) {
84
//            throw new IllegalArgumentException("script can't be null");
85
//        }
86
//        this.scripts.remove(script);
87
//    }
88

    
89
    @Override
90
    public MutableSymbolTable clone() throws CloneNotSupportedException {
91
        throw new CloneNotSupportedException("Not supported yet."); 
92
    }
93
}