4 |
import java.util.List; |
import java.util.List; |
5 |
import java.util.TreeMap; |
import java.util.TreeMap; |
6 |
|
|
7 |
|
import org.apache.log4j.Logger; |
8 |
import org.geotools.feature.NameImpl; |
import org.geotools.feature.NameImpl; |
9 |
import org.opengis.feature.type.Name; |
import org.opengis.feature.type.Name; |
10 |
|
|
11 |
import skrueger.AttributeMetadata; |
import skrueger.AttributeMetadata; |
12 |
|
import skrueger.i8n.I8NUtil; |
13 |
|
|
14 |
/** |
/** |
15 |
* An extension of TreeMap, that is copyable in the sense of the {@link Copyable} interface |
* An extension of TreeMap, that is copyable in the sense of the {@link Copyable} interface |
16 |
*/ |
*/ |
17 |
public class AttributeMetadataMap extends TreeMap<Name, 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 |
|
|
21 |
|
|
22 |
/** |
/** |
23 |
* @Deprecated use get(Name name) or get(String localName) |
* @Deprecated use get(Name name) or get(String localName) |
24 |
*/ |
*/ |
25 |
@Deprecated |
@Deprecated |
26 |
public AttributeMetadata get(Object key) { |
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); |
return super.get(key); |
31 |
} |
} |
32 |
|
|
33 |
public AttributeMetadata get(Name name) { |
public AttributeMetadata get(Name name) { |
34 |
final AttributeMetadata attributeMetadata = super.get(name); |
final AttributeMetadata attributeMetadata = super.get(name); |
35 |
if (attributeMetadata == null && name != null && !name.getLocalPart().trim().isEmpty()) { |
if (attributeMetadata == null && name != null && !name.getLocalPart().trim().isEmpty()) { |
66 |
list.addAll(values()); |
list.addAll(values()); |
67 |
return list; |
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 |
} |
} |