root / branches / v2_0_0_prep / libraries / libFMap_data / src / org / gvsig / fmap / data / AbstractDataParameters.java @ 23600
History | View | Annotate | Download (4.41 KB)
1 |
package org.gvsig.fmap.data; |
---|---|
2 |
|
3 |
import java.util.Collection; |
4 |
import java.util.Collections; |
5 |
import java.util.HashMap; |
6 |
import java.util.Iterator; |
7 |
import java.util.Map; |
8 |
import java.util.Set; |
9 |
|
10 |
|
11 |
/* gvSIG. Geographic Information System of the Valencian Government
|
12 |
*
|
13 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
14 |
* of the Valencian Government (CIT)
|
15 |
*
|
16 |
* This program is free software; you can redistribute it and/or
|
17 |
* modify it under the terms of the GNU General Public License
|
18 |
* as published by the Free Software Foundation; either version 2
|
19 |
* of the License, or (at your option) any later version.
|
20 |
*
|
21 |
* This program is distributed in the hope that it will be useful,
|
22 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
23 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
24 |
* GNU General Public License for more details.
|
25 |
*
|
26 |
* You should have received a copy of the GNU General Public License
|
27 |
* along with this program; if not, write to the Free Software
|
28 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
29 |
* MA 02110-1301, USA.
|
30 |
*
|
31 |
*/
|
32 |
|
33 |
/*
|
34 |
* AUTHORS (In addition to CIT):
|
35 |
* 2008 IVER T.I. S.A. {{Task}}
|
36 |
*/
|
37 |
|
38 |
/**
|
39 |
*
|
40 |
*/
|
41 |
/**
|
42 |
* @author jmvivo
|
43 |
*
|
44 |
*/
|
45 |
public abstract class AbstractDataParameters implements DataParameters { |
46 |
private Map params; |
47 |
private Map defaultParams; |
48 |
|
49 |
public AbstractDataParameters() {
|
50 |
this.params = new HashMap(); |
51 |
this.defaultParams = this.createDefaultValuesMap(); |
52 |
this.clear();
|
53 |
} |
54 |
|
55 |
/**
|
56 |
* Create a new map with defaultValues
|
57 |
*
|
58 |
* @return Map
|
59 |
*/
|
60 |
protected abstract Map createDefaultValuesMap(); |
61 |
|
62 |
/* (non-Javadoc)
|
63 |
* @see java.util.Map#containsKey(java.lang.Object)
|
64 |
*/
|
65 |
public boolean containsKey(Object key) { |
66 |
return this.params.containsKey(key); |
67 |
} |
68 |
|
69 |
/* (non-Javadoc)
|
70 |
* @see java.util.Map#containsValue(java.lang.Object)
|
71 |
*/
|
72 |
public final boolean containsValue(Object value) { |
73 |
return this.params.containsValue(value); |
74 |
} |
75 |
|
76 |
/**
|
77 |
* Unsupported
|
78 |
*
|
79 |
* @see java.util.Map#entrySet()
|
80 |
*
|
81 |
* @throws UnsupportedOperationException
|
82 |
*
|
83 |
*/
|
84 |
public final Set entrySet() { |
85 |
return Collections.unmodifiableSet(this.params.entrySet()); |
86 |
} |
87 |
|
88 |
/**
|
89 |
* @see java.util.Map#isEmpty()
|
90 |
*
|
91 |
* @return false
|
92 |
*/
|
93 |
public boolean isEmpty() { |
94 |
return false; |
95 |
} |
96 |
|
97 |
/*
|
98 |
* (non-Javadoc)
|
99 |
*
|
100 |
* @see java.util.Map#size()
|
101 |
*/
|
102 |
public final int size() { |
103 |
return this.params.size(); |
104 |
} |
105 |
|
106 |
/**
|
107 |
* Like {@link Map#keySet()} but read only
|
108 |
*
|
109 |
* @see java.util.Map#keySet()
|
110 |
*
|
111 |
* @return {@link java.util.Collections#unmodifiableSet(Set)}
|
112 |
*
|
113 |
*/
|
114 |
public final Set keySet() { |
115 |
return Collections.unmodifiableSet(this.params.keySet()); |
116 |
} |
117 |
|
118 |
/**
|
119 |
* Returs default values keyset like {@link AbstractDataParameters#keySet()}
|
120 |
*
|
121 |
* @see java.util.Map#keySet()
|
122 |
*
|
123 |
* @return {@link java.util.Collections#unmodifiableSet(Set)}
|
124 |
*
|
125 |
*/
|
126 |
public final Set defaultValueskeySet() { |
127 |
return Collections.unmodifiableSet(this.defaultParams.keySet()); |
128 |
} |
129 |
|
130 |
/*
|
131 |
* (no javadoc)
|
132 |
*
|
133 |
* @see java.util.Map#putAll(java.util.Map)
|
134 |
*/
|
135 |
public final void putAll(Map t) { |
136 |
this.params.putAll(t);
|
137 |
} |
138 |
|
139 |
/**
|
140 |
* Puts only the values of the defaut entries.<br>
|
141 |
* The others will be ignored
|
142 |
*
|
143 |
* @see java.util.Map#putAll(java.util.Map)
|
144 |
*/
|
145 |
public final void putAllDefaultValues(Map t) { |
146 |
Iterator iter = this.defaultParams.keySet().iterator(); |
147 |
Object key;
|
148 |
while (iter.hasNext()) {
|
149 |
key = iter.next(); |
150 |
if (t.containsKey(key)) {
|
151 |
this.params.put(key, t.get(key));
|
152 |
} |
153 |
} |
154 |
} |
155 |
|
156 |
/**
|
157 |
* For standart entries resets to default value.<br>
|
158 |
* The others entries will be removed.
|
159 |
*
|
160 |
* @throws {@link UnsupportedOperationException} if key is in the standart
|
161 |
* entries
|
162 |
*
|
163 |
* @see java.util.Map#remove(java.lang.Object)
|
164 |
*/
|
165 |
public Object remove(Object key) { |
166 |
if (this.defaultParams.containsKey(key)) { |
167 |
return this.params.put(key, this.defaultParams.get(key)); |
168 |
} |
169 |
return this.params.remove(key); |
170 |
} |
171 |
|
172 |
/**
|
173 |
* Like {@link Map#values()} but read only
|
174 |
*
|
175 |
* @see Map#values()
|
176 |
*
|
177 |
* @return {@link java.util.Collections#unmodifiableCollection(Collection))}
|
178 |
*
|
179 |
*/
|
180 |
public final Collection values() { |
181 |
return Collections.unmodifiableCollection(this.params.values()); |
182 |
} |
183 |
|
184 |
/*
|
185 |
* (non-Javadoc)
|
186 |
*
|
187 |
* @see java.util.Map#get(java.lang.Object)
|
188 |
*/
|
189 |
public final Object get(Object key) { |
190 |
return this.params.get(key); |
191 |
} |
192 |
|
193 |
public Object put(Object key, Object value) { |
194 |
return this.params.put(key, value); |
195 |
} |
196 |
|
197 |
public void clear() { |
198 |
params.clear(); |
199 |
params.putAll(defaultParams); |
200 |
} |
201 |
|
202 |
|
203 |
|
204 |
|
205 |
} |