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