1 |
package skrueger.geotools; |
package skrueger.geotools; |
2 |
|
|
3 |
|
import java.util.ArrayList; |
4 |
|
import java.util.List; |
5 |
import java.util.TreeMap; |
import java.util.TreeMap; |
6 |
|
|
7 |
import skrueger.AttributeMetaData; |
import org.apache.log4j.Logger; |
8 |
|
import org.geotools.feature.NameImpl; |
9 |
|
import org.opengis.feature.type.Name; |
10 |
|
|
11 |
|
import skrueger.AttributeMetadata; |
12 |
|
import skrueger.i8n.I8NUtil; |
13 |
|
|
14 |
/** |
/** |
15 |
* An extension of TreeMap, that is clonable in the sense of |
* An extension of TreeMap, that is copyable in the sense of the {@link Copyable} interface |
|
* |
|
|
* @author stefan |
|
|
* |
|
16 |
*/ |
*/ |
17 |
public class AttributeMetadataMap extends TreeMap<Integer, AttributeMetaData> |
public class AttributeMetadataMap extends TreeMap<Name, AttributeMetadata> |
18 |
implements Copyable<AttributeMetadataMap> { |
implements Copyable<AttributeMetadataMap> { |
19 |
|
static private final Logger LOGGER = Logger.getLogger(AttributeMetadataMap.class); |
20 |
public AttributeMetadataMap() { |
|
21 |
|
|
22 |
|
/** |
23 |
|
* @Deprecated use get(Name name) or get(String localName) |
24 |
|
*/ |
25 |
|
@Deprecated |
26 |
|
public AttributeMetadata get(Object key) { |
27 |
|
LOGGER.warn("PLEASE DONT USE get(Object) any MORE!"); |
28 |
|
LOGGER.warn("PLEASE DONT USE get(Object) any MORE!"); |
29 |
|
LOGGER.warn("PLEASE DONT USE get(Object) any MORE!"); |
30 |
|
return super.get(key); |
31 |
|
} |
32 |
|
|
33 |
|
public AttributeMetadata get(Name name) { |
34 |
|
final AttributeMetadata attributeMetadata = super.get(name); |
35 |
|
if (attributeMetadata == null && name != null && !name.getLocalPart().trim().isEmpty()) { |
36 |
|
put(name,new AttributeMetadata(name)); |
37 |
|
return super.get(name); |
38 |
|
} |
39 |
|
return attributeMetadata; |
40 |
} |
} |
41 |
|
|
42 |
|
public AttributeMetadata get(String localName) { |
43 |
|
return this.get(new NameImpl(localName)); |
44 |
|
} |
45 |
|
|
46 |
@Override |
@Override |
47 |
public AttributeMetadataMap copyTo(AttributeMetadataMap amdMap) { |
public AttributeMetadataMap copyTo(AttributeMetadataMap amdMap) { |
48 |
|
|
49 |
amdMap.clear(); |
amdMap.clear(); |
50 |
|
|
51 |
for (Integer key : keySet()) { |
for (Name key : keySet()) { |
52 |
AttributeMetaData attributeMetaData = get(key); |
AttributeMetadata attributeMetaData = get(key); |
53 |
amdMap.put(key, attributeMetaData.copy()); |
amdMap.put(key, attributeMetaData.copy()); |
54 |
} |
} |
55 |
return amdMap; |
return amdMap; |
60 |
AttributeMetadataMap copy = new AttributeMetadataMap(); |
AttributeMetadataMap copy = new AttributeMetadataMap(); |
61 |
return copyTo(copy); |
return copyTo(copy); |
62 |
} |
} |
63 |
|
|
64 |
|
public List<AttributeMetadata> sortedValues() { |
65 |
|
ArrayList<AttributeMetadata> list = new ArrayList<AttributeMetadata>(); |
66 |
|
list.addAll(values()); |
67 |
|
return list; |
68 |
|
} |
69 |
|
|
70 |
|
/** |
71 |
|
* @return a number between 0 (bad) and 1 (good) that is calculated from the amount of translation available in the visible attributes |
72 |
|
*/ |
73 |
|
public double getQuality(List<String> languages) { |
74 |
|
int allVisible = 0; |
75 |
|
double colQmSum = 0.; |
76 |
|
for (final AttributeMetadata oneCol : values()) { |
77 |
|
|
78 |
|
if (oneCol.isVisible()) { |
79 |
|
allVisible++; |
80 |
|
colQmSum += oneCol.getQuality(languages); |
81 |
|
} |
82 |
|
} |
83 |
|
|
84 |
|
if (allVisible > 0) |
85 |
|
return colQmSum / allVisible; |
86 |
|
else |
87 |
|
return 1.; |
88 |
|
|
89 |
|
} |
90 |
} |
} |