1 |
package skrueger.geotools; |
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.List; |
5 |
import java.util.SortedMap; |
6 |
import java.util.TreeMap; |
7 |
|
8 |
import org.geotools.feature.NameImpl; |
9 |
import org.opengis.feature.type.Name; |
10 |
|
11 |
import skrueger.AttributeMetadata; |
12 |
|
13 |
/** |
14 |
* An extension of TreeMap, that is copyable in the sense of the {@link Copyable} interface |
15 |
*/ |
16 |
public class AttributeMetadataMap extends TreeMap<Name, AttributeMetadata> |
17 |
implements Copyable<AttributeMetadataMap> { |
18 |
|
19 |
/** |
20 |
* @Deprecated use get(Name name) or get(String localName) |
21 |
*/ |
22 |
@Deprecated |
23 |
public AttributeMetadata get(Object key) { |
24 |
return super.get(key); |
25 |
} |
26 |
|
27 |
public AttributeMetadata get(Name name) { |
28 |
final AttributeMetadata attributeMetadata = super.get(name); |
29 |
if (attributeMetadata == null) { |
30 |
put(name,new AttributeMetadata(name)); |
31 |
return super.get(name); |
32 |
} |
33 |
return attributeMetadata; |
34 |
} |
35 |
|
36 |
public AttributeMetadata get(String localName) { |
37 |
return this.get(new NameImpl(localName)); |
38 |
} |
39 |
|
40 |
@Override |
41 |
public AttributeMetadataMap copyTo(AttributeMetadataMap amdMap) { |
42 |
|
43 |
amdMap.clear(); |
44 |
|
45 |
for (Name key : keySet()) { |
46 |
AttributeMetadata attributeMetaData = get(key); |
47 |
amdMap.put(key, attributeMetaData.copy()); |
48 |
} |
49 |
return amdMap; |
50 |
} |
51 |
|
52 |
@Override |
53 |
public AttributeMetadataMap copy() { |
54 |
AttributeMetadataMap copy = new AttributeMetadataMap(); |
55 |
return copyTo(copy); |
56 |
} |
57 |
|
58 |
public List<AttributeMetadata> sortedValues() { |
59 |
ArrayList<AttributeMetadata> list = new ArrayList<AttributeMetadata>(); |
60 |
list.addAll(values()); |
61 |
return list; |
62 |
} |
63 |
} |