/[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 833 - (hide annotations)
Thu May 6 19:50:32 2010 UTC (14 years, 9 months ago) by alfonx
File MIME type: text/plain
File size: 4664 byte(s)
Organized Imports and minor improvements in IOUtil.readURLtoString
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 772 import skrueger.AttributeMetadataInterface;
14 alfonx 769 import skrueger.QualityQuantizable;
15 alfonx 533 import skrueger.i8n.Translation;
16 alfonx 464
17 alfonx 420 /**
18 alfonx 769 * The {@link AttributeMetadataMap} is a {@link Map} holding {@link AMD_IMPL}
19     * object for {@link Name} keys. It's an extension of a {@link TreeMap}. It's
20     * copyable in the sense of the {@link Copyable} interface.<br>
21 alfonx 534 * The {@link #get(Name)} and {@link #get(String)} methods will never return
22 alfonx 769 * <code>null</code>, but rather create a default {@link AMD_IMPL} on-the-fly.
23 alfonx 420 */
24 alfonx 772 public abstract class AttributeMetadataMap<AMD_IMPL extends AttributeMetadataInterface>
25 alfonx 797 extends TreeMap<Name, AMD_IMPL> implements
26 alfonx 769 Copyable<AttributeMetadataMap>, QualityQuantizable {
27    
28     private static final long serialVersionUID = 4936966916517396063L;
29    
30     protected static final Logger LOGGER = Logger
31 alfonx 534 .getLogger(AttributeMetadataMap.class);
32    
33     /**
34 alfonx 769 * A list of default languages used when creating default {@link AMD_IMPL}
35     * on-the-fly. If not initialized by a constructor, it will be
36     * {@link Translation#getActiveLang()} only.
37 alfonx 534 **/
38 alfonx 769 protected final List<String> langs;
39 alfonx 534
40 alfonx 658 /**
41 alfonx 769 * AttributeMetadataMap is based on {@link Translation} and would like to
42     * know how many languages are supported, so the needed defaults can be
43     * created.<br/>
44     * If you use this constructor, it will be initialized to only use one
45     * language, which is {@link Translation.getActiveLang()}.
46 alfonx 658 */
47 alfonx 533 public AttributeMetadataMap() {
48     langs = new ArrayList<String>();
49     langs.add(Translation.getActiveLang());
50     }
51 alfonx 534
52     /**
53     * Creates an {@link AttributeMetadataMap} and sets the list of default
54     * languages.
55     */
56     public AttributeMetadataMap(final List<String> defLanguages) {
57     langs = defLanguages;
58     }
59    
60     /**
61     * Creates an {@link AttributeMetadataMap} and sets the list of default
62     * languages.
63     */
64 alfonx 769 public AttributeMetadataMap(final String[] langs) {
65     this.langs = new ArrayList<String>(java.util.Arrays.asList(langs));
66 alfonx 533 }
67    
68 alfonx 464 /**
69 alfonx 534 * Copies all its values to another {@link AttributeMetadataMap}. @see
70     * {@link Copyable} interface.
71     */
72 alfonx 420 @Override
73 alfonx 772 public AttributeMetadataMap<? extends AttributeMetadataInterface> copyTo(AttributeMetadataMap amdMap) {
74 alfonx 534
75 alfonx 420 amdMap.clear();
76 alfonx 534
77 alfonx 797 for (final Name key : keySet()) {
78 alfonx 769 final AMD_IMPL AMD_IMPL = get(key);
79     amdMap.put(key, AMD_IMPL.copy());
80 alfonx 420 }
81     return amdMap;
82     }
83    
84 alfonx 534 /**
85 alfonx 770 * Returns the {@link AMD_IMPL} for a given {@link NameImpl}. May return
86 alfonx 772 * <code>null</code> or create a default {@link AttributeMetadataInterface} depending
87 alfonx 769 * on whether this method is overwritten. fly.
88 alfonx 534 */
89 alfonx 797 public AMD_IMPL get(final Name name) {
90 alfonx 769 return super.get(name);
91 alfonx 534 }
92    
93     /**
94     * @Deprecated use get(Name name) or get(String localName)
95     */
96 alfonx 797 @Deprecated
97 alfonx 420 @Override
98 alfonx 769 public AMD_IMPL get(final Object key) {
99     LOGGER.error("PLEASE DONT USE get(Object) any MORE!");
100 alfonx 534 return super.get(key);
101 alfonx 420 }
102 alfonx 464
103 alfonx 534 /**
104 alfonx 769 * Returns the {@link AMD_IMPL} for a given {@link Name}. Never returns
105     * <code>null</code>, but rather creates a default {@link AMD_IMPL} on the
106     * fly.
107 alfonx 534 */
108 alfonx 769 public AMD_IMPL get(final String localName) {
109     if (localName == null)
110     return null;
111 alfonx 534 return this.get(new NameImpl(localName));
112 alfonx 464 }
113 alfonx 518
114 alfonx 534 public List<String> getLanguages() {
115     return langs;
116     }
117    
118 alfonx 518 /**
119 alfonx 534 * @return a number between 0. (bad) and 1. (good) that is calculated from
120     * the amount of translation available in the visible attributes
121 alfonx 518 */
122 alfonx 769 @Override
123 alfonx 534 public double getQuality(final List<String> languages) {
124 alfonx 518 int allVisible = 0;
125     double colQmSum = 0.;
126 alfonx 769 for (final AMD_IMPL oneCol : values()) {
127 alfonx 534
128 alfonx 769 if (oneCol.isVisible() && oneCol instanceof QualityQuantizable) {
129 alfonx 518 allVisible++;
130 alfonx 769 colQmSum += ((QualityQuantizable) oneCol).getQuality(languages);
131 alfonx 518 }
132     }
133    
134     if (allVisible > 0)
135     return colQmSum / allVisible;
136     else
137     return 1.;
138    
139     }
140 alfonx 533
141 alfonx 534 /**
142 alfonx 769 * @return List of {@link AMD_IMPL} objects ordered by their weight.
143     * (heavier => further down)
144 alfonx 534 */
145 alfonx 769 public List<AMD_IMPL> sortedValues() {
146     final ArrayList<AMD_IMPL> list = new ArrayList<AMD_IMPL>();
147 alfonx 534 list.addAll(values());
148     Collections.sort(list);
149     return list;
150 alfonx 533 }
151 alfonx 534
152     /**
153 alfonx 769 * @return List of only the visible {@link AMD_IMPL} objects ordered by
154     * their weight. (heavier => further down)
155 alfonx 534 */
156 alfonx 769 public List<AMD_IMPL> sortedValuesVisibleOnly() {
157     final ArrayList<AMD_IMPL> list = new ArrayList<AMD_IMPL>();
158     for (final AMD_IMPL atm : sortedValues()) {
159 alfonx 534 if (atm.isVisible())
160     list.add(atm);
161     }
162     return list;
163     }
164 alfonx 833
165 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