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 @ 45153

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

    
46
    @Override
47
    public void addFunction(Function function) {
48
        super.addFunction(function);
49
    }
50

    
51
    @Override
52
    public void addFunctions(Collection<Function> functions) {
53
        for (Function function : functions) {
54
            this.addFunction(function);
55
        }
56
    }
57

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

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

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

    
93
    @Override
94
    public MutableSymbolTable clone() throws CloneNotSupportedException {
95
        throw new CloneNotSupportedException("Not supported yet."); 
96
    }
97
}