/[schmitzm]/trunk/src/skrueger/geotools/AttributeMetadataMap.java
ViewVC logotype

Annotation of /trunk/src/skrueger/geotools/AttributeMetadataMap.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 534 - (hide annotations)
Fri Nov 20 10:28:01 2009 UTC (15 years, 3 months ago) by alfonx
Original Path: branches/1.0-gt2-2.6/src/skrueger/geotools/AttributeMetadataMap.java
File MIME type: text/plain
File size: 4761 byte(s)
* Added more documentation to AttributeMetadataMap
* Changed StyledFeatureCollectionTableModel to show the columns in the order that is defined in the AttributeMetaData.

1 alfonx 420 package skrueger.geotools;
2    
3 alfonx 464 import java.util.ArrayList;
4 alfonx 533 import java.util.Collections;
5 alfonx 464 import java.util.List;
6 alfonx 534 import java.util.Map;
7 alfonx 420 import java.util.TreeMap;
8    
9 alfonx 518 import org.apache.log4j.Logger;
10 alfonx 464 import org.geotools.feature.NameImpl;
11     import org.opengis.feature.type.Name;
12 alfonx 420
13 alfonx 464 import skrueger.AttributeMetadata;
14 alfonx 533 import skrueger.i8n.Translation;
15 alfonx 464
16 alfonx 420 /**
17 alfonx 534 * The {@link AttributeMetadataMap} is a {@link Map} holding
18     * {@link AttributeMetadata} object for {@link Name} keys. It's an extension of
19     * a {@link TreeMap}. It's copyable in the sense of the {@link Copyable}
20     * interface.<br>
21     * The {@link #get(Name)} and {@link #get(String)} methods will never return
22     * <code>null</code>, but rather create a default {@link AttributeMetadata}
23     * on-the-fly.
24 alfonx 420 */
25 alfonx 464 public class AttributeMetadataMap extends TreeMap<Name, AttributeMetadata>
26 alfonx 420 implements Copyable<AttributeMetadataMap> {
27 alfonx 534 static private final Logger LOGGER = Logger
28     .getLogger(AttributeMetadataMap.class);
29    
30     /**
31     * A list of default languages used when creating default
32     * {@link AttributeMetadata} on-the-fly. If not initialized by a
33     * constructor, it will be {@link Translation#getActiveLang()} only.
34     **/
35     private final List<String> langs;
36    
37     @Deprecated
38 alfonx 533 public AttributeMetadataMap() {
39     langs = new ArrayList<String>();
40     langs.add(Translation.getActiveLang());
41     }
42 alfonx 534
43     /**
44     * Creates an {@link AttributeMetadataMap} and sets the list of default
45     * languages.
46     */
47     public AttributeMetadataMap(final List<String> defLanguages) {
48     langs = defLanguages;
49     }
50    
51     /**
52     * Creates an {@link AttributeMetadataMap} and sets the list of default
53     * languages.
54     */
55     public AttributeMetadataMap(final String[] strings) {
56 alfonx 533 langs = new ArrayList<String>(java.util.Arrays.asList(strings));
57     }
58    
59 alfonx 464 /**
60 alfonx 534 * Returns a deep-copy. @see {@link Copyable} interface
61 alfonx 464 */
62 alfonx 534 @Override
63     public AttributeMetadataMap copy() {
64     final AttributeMetadataMap copy = new AttributeMetadataMap(langs);
65     return copyTo(copy);
66 alfonx 420 }
67 alfonx 464
68 alfonx 534 /**
69     * Copies all its values to another {@link AttributeMetadataMap}. @see
70     * {@link Copyable} interface.
71     */
72 alfonx 420 @Override
73 alfonx 534 public AttributeMetadataMap copyTo(final AttributeMetadataMap amdMap) {
74    
75 alfonx 420 amdMap.clear();
76 alfonx 534
77     for (final Name key : keySet()) {
78     final AttributeMetadata attributeMetaData = get(key);
79 alfonx 420 amdMap.put(key, attributeMetaData.copy());
80     }
81     return amdMap;
82     }
83    
84 alfonx 534 /**
85     * Returns the {@link AttributeMetadata} for a given {@link Name}. Never
86     * returns <code>null</code>, but rather creates a default
87     * {@link AttributeMetadata} on the fly.
88     */
89     public AttributeMetadata get(final Name name) {
90     final AttributeMetadata attributeMetadata = super.get(name);
91     if (attributeMetadata == null && name != null
92     && !name.getLocalPart().trim().isEmpty()) {
93     put(name, new AttributeMetadata(name, langs));
94     return super.get(name);
95     }
96     return attributeMetadata;
97     }
98    
99     /**
100     * @Deprecated use get(Name name) or get(String localName)
101     */
102 alfonx 420 @Override
103 alfonx 534 @Deprecated
104     public AttributeMetadata get(final Object key) {
105     LOGGER.warn("PLEASE DONT USE get(Object) any MORE!");
106     LOGGER.warn("PLEASE DONT USE get(Object) any MORE!");
107     LOGGER.warn("PLEASE DONT USE get(Object) any MORE!");
108     return super.get(key);
109 alfonx 420 }
110 alfonx 464
111 alfonx 534 /**
112     * Returns the {@link AttributeMetadata} for a given {@link Name}. Never
113     * returns <code>null</code>, but rather creates a default
114     * {@link AttributeMetadata} on the fly.
115     */
116     public AttributeMetadata get(final String localName) {
117     return this.get(new NameImpl(localName));
118 alfonx 464 }
119 alfonx 518
120 alfonx 534 public List<String> getLanguages() {
121     return langs;
122     }
123    
124 alfonx 518 /**
125 alfonx 534 * @return a number between 0. (bad) and 1. (good) that is calculated from
126     * the amount of translation available in the visible attributes
127 alfonx 518 */
128 alfonx 534 public double getQuality(final List<String> languages) {
129 alfonx 518 int allVisible = 0;
130     double colQmSum = 0.;
131     for (final AttributeMetadata oneCol : values()) {
132 alfonx 534
133 alfonx 518 if (oneCol.isVisible()) {
134     allVisible++;
135     colQmSum += oneCol.getQuality(languages);
136     }
137     }
138    
139     if (allVisible > 0)
140     return colQmSum / allVisible;
141     else
142     return 1.;
143    
144     }
145 alfonx 533
146 alfonx 534
147     /**
148     * @return List of {@link AttributeMetadata} objects ordered by their
149     * weight. (heavier => further down)
150     */
151     public List<AttributeMetadata> sortedValues() {
152     final ArrayList<AttributeMetadata> list = new ArrayList<AttributeMetadata>();
153     list.addAll(values());
154     Collections.sort(list);
155     return list;
156 alfonx 533 }
157 alfonx 534
158     /**
159     * @return List of only the visible {@link AttributeMetadata} objects
160     * ordered by their weight. (heavier => further down)
161     */
162     public List<AttributeMetadata> sortedValuesVisibleOnly() {
163     final ArrayList<AttributeMetadata> list = new ArrayList<AttributeMetadata>();
164     for (final AttributeMetadata atm : sortedValues()) {
165     if (atm.isVisible())
166     list.add(atm);
167     }
168     return list;
169     }
170 alfonx 420 }

Properties

Name Value
svn:eol-style native
svn:keywords Id URL
svn:mime-type text/plain

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26