/[schmitzm]/branches/1.0-gt2-2.6/src/skrueger/geotools/AttributeMetadataMap.java
ViewVC logotype

Diff of /branches/1.0-gt2-2.6/src/skrueger/geotools/AttributeMetadataMap.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 420 by alfonx, Thu Oct 1 20:22:48 2009 UTC revision 533 by alfonx, Thu Nov 19 17:27:01 2009 UTC
# Line 1  Line 1 
1  package skrueger.geotools;  package skrueger.geotools;
2    
3    import java.util.ArrayList;
4    import java.util.Collections;
5    import java.util.List;
6  import java.util.TreeMap;  import java.util.TreeMap;
7    
8  import skrueger.AttributeMetaData;  import org.apache.log4j.Logger;
9    import org.geotools.feature.NameImpl;
10    import org.opengis.feature.type.Name;
11    
12    import cern.colt.Arrays;
13    
14    import skrueger.AttributeMetadata;
15    import skrueger.i8n.I8NUtil;
16    import skrueger.i8n.Translation;
17    
18  /**  /**
19   * 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  
  *  
20   */   */
21  public class AttributeMetadataMap extends TreeMap<Integer, AttributeMetaData>  public class AttributeMetadataMap extends TreeMap<Name, AttributeMetadata>
22                  implements Copyable<AttributeMetadataMap> {                  implements Copyable<AttributeMetadataMap> {
23            static private final Logger LOGGER = Logger.getLogger(AttributeMetadataMap.class);
24            private List<String> langs;
25            
26            public AttributeMetadataMap(List<String> defLanguages) {
27                    langs = defLanguages;
28            }
29            
30            @Deprecated
31          public AttributeMetadataMap() {          public AttributeMetadataMap() {
32                    langs = new ArrayList<String>();
33                    langs.add(Translation.getActiveLang());
34            }
35            
36            
37            public AttributeMetadataMap(String[] strings) {
38                    langs = new ArrayList<String>(java.util.Arrays.asList(strings));
39          }          }
40    
41            /**
42             * @Deprecated use get(Name name) or get(String localName)
43             */
44            @Deprecated
45            public AttributeMetadata get(Object key) {
46                    LOGGER.warn("PLEASE DONT USE get(Object) any MORE!");
47                    LOGGER.warn("PLEASE DONT USE get(Object) any MORE!");
48                    LOGGER.warn("PLEASE DONT USE get(Object) any MORE!");
49                    return super.get(key);
50            }
51            
52            public AttributeMetadata get(Name name) {
53                    final AttributeMetadata attributeMetadata = super.get(name);
54                    if (attributeMetadata == null && name != null && !name.getLocalPart().trim().isEmpty()) {
55                            put(name,new AttributeMetadata(name, langs));
56                            return super.get(name);
57                    }
58                    return attributeMetadata;
59            }
60    
61            public AttributeMetadata get(String localName) {
62                    return this.get(new NameImpl(localName));
63            }
64            
65          @Override          @Override
66          public AttributeMetadataMap copyTo(AttributeMetadataMap amdMap) {          public AttributeMetadataMap copyTo(AttributeMetadataMap amdMap) {
67                                    
68                  amdMap.clear();                  amdMap.clear();
69                                    
70                  for (Integer key : keySet()) {                  for (Name key : keySet()) {
71                          AttributeMetaData attributeMetaData = get(key);                          AttributeMetadata attributeMetaData = get(key);
72                          amdMap.put(key, attributeMetaData.copy());                          amdMap.put(key, attributeMetaData.copy());
73                  }                  }
74                  return amdMap;                  return amdMap;
# Line 30  public class AttributeMetadataMap extend Line 76  public class AttributeMetadataMap extend
76    
77          @Override          @Override
78          public AttributeMetadataMap copy() {          public AttributeMetadataMap copy() {
79                  AttributeMetadataMap copy = new AttributeMetadataMap();                  AttributeMetadataMap copy = new AttributeMetadataMap(langs);
80                  return copyTo(copy);                  return copyTo(copy);
81          }          }
82    
83            public List<AttributeMetadata> sortedValues() {
84                    ArrayList<AttributeMetadata> list = new ArrayList<AttributeMetadata>();
85                    list.addAll(values());
86                    return list;
87            }
88    
89            /**
90             * @return a number between 0 (bad) and 1 (good) that is calculated from the amount of translation available in the visible attributes
91             */
92            public double getQuality(List<String> languages) {
93                    int allVisible = 0;
94                    double colQmSum = 0.;
95                    for (final AttributeMetadata oneCol : values()) {
96                            
97                            if (oneCol.isVisible()) {
98                                    allVisible++;
99                                    colQmSum += oneCol.getQuality(languages);
100                            }
101                    }
102    
103                    if (allVisible > 0)
104                            return colQmSum / allVisible;
105                    else
106                            return 1.;
107    
108            }
109    
110            public List<String> getLanguages() {
111                    return langs;
112            }
113  }  }

Legend:
Removed from v.420  
changed lines
  Added in v.533

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26