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