Statistics
| Revision:

gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / main / java / org / gvsig / tools / dynobject / impl / DefaultTags.java @ 1225

History | View | Annotate | Download (1.92 KB)

1
package org.gvsig.tools.dynobject.impl;
2

    
3
import java.util.HashMap;
4
import java.util.Iterator;
5
import java.util.Map;
6

    
7
import org.gvsig.tools.ToolsLocator;
8
import org.gvsig.tools.dataTypes.CoercionException;
9
import org.gvsig.tools.dataTypes.DataTypes;
10
import org.gvsig.tools.dataTypes.DataTypesManager;
11
import org.gvsig.tools.dynobject.Tags;
12

    
13
public class DefaultTags implements Tags{
14

    
15
        
16
        private Map tags = null;
17

    
18
        public Object get(String name) {
19
                if(this.tags  == null){
20
                        return null;
21
                }
22
                return this.tags.get(name.toLowerCase());
23
        }
24
        
25
        public Object get(String name, int type) throws CoercionException {
26
                if(this.tags == null){
27
                        return null;
28
                }
29
                DataTypesManager dataman = ToolsLocator.getDataTypesManager();
30
                return dataman.coerce(type, this.tags.get(name.toLowerCase()));
31
        }
32
        
33
        public void set(String name, Object value) {
34
                if(this.tags == null){
35
                        this.tags  = new HashMap();
36
                }
37
                this.tags.put(name.toLowerCase(), value);
38
        }
39
 
40
        public boolean has(String name) {
41
                if(this.tags == null || name == null){
42
                        return false;
43
                }                
44
                return this.tags.containsKey(name.toLowerCase());
45
        }
46
        
47
        public int getInt(String name) throws CoercionException {
48
                Object x = this.get(name.toLowerCase(),DataTypes.INT);
49
                if( x==null ) {
50
                        return 0;
51
                }
52
                return ((Integer)x).intValue();
53
        }
54
        
55
        public boolean getBoolean(String name) throws CoercionException {
56
                Object x = this.get(name.toLowerCase(),DataTypes.BOOLEAN);
57
                if( x==null ) {
58
                        return false;
59
                }
60
                return ((Boolean)x).booleanValue();
61
        }
62
        
63
        public Iterator getKeys() {
64
                if(this.tags == null){
65
                        return null;
66
                }
67
                return this.tags.keySet().iterator();
68
        }
69
        
70
        public Object clone() throws CloneNotSupportedException {
71
                DefaultTags newTags = (DefaultTags) super.clone();
72
                newTags.add(this);
73
                return newTags;
74
        }        
75
        
76
        public void add(Tags tags) {
77
                Iterator it = tags.getKeys();
78
                if(it != null){
79
                        while(it.hasNext()){
80
                                String key = (String) it.next();
81
                                this.set(key, tags.get(key));
82
                        }
83
                }
84
        }
85
}