/[schmitzm]/trunk/src/skrueger/AbstractAttributeMetadata.java
ViewVC logotype

Annotation of /trunk/src/skrueger/AbstractAttributeMetadata.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 769 - (hide annotations)
Sun Mar 21 11:02:34 2010 UTC (14 years, 11 months ago) by alfonx
File MIME type: text/plain
File size: 3977 byte(s)
Made an interface and a Abstract class for AttributeMetaData
1 alfonx 769 package skrueger;
2    
3     import java.util.HashSet;
4    
5     import org.geotools.feature.NameImpl;
6     import org.opengis.feature.type.Name;
7    
8     import skrueger.geotools.StyledLayerUtil;
9     import skrueger.i8n.Translation;
10    
11     public abstract class AbstractAttributeMetadata implements AttributeMetadata {
12    
13     /** The Name of the attribute. This is the 'primary key' **/
14     protected Name name;
15    
16     /** {@link Translation}s of the attribute's title **/
17     protected Translation title = new Translation();
18    
19     /** {@link Translation}s of the attribute's description **/
20     protected Translation desc = new Translation();
21    
22     /**
23     * Allows to define general NODATA values for an attribute. e.g. -9999 can
24     * be set and will always be interpreted as NULL internally and will usually
25     * be ignored. This overcomes the problem, that
26     **/
27     protected HashSet<Object> nodataValues = new HashSet<Object>();
28    
29     /**
30     * The unit append to all visualizations of values of this attribute (is not
31     * null)
32     **/
33     protected String unit = "";
34    
35     /** Is the attribute visible to the user or ignored where possible **/
36     protected boolean visible = true;
37    
38     @Override
39     public Translation getTitle() {
40     return title;
41     }
42    
43     @Override
44     public String getUnit() {
45     return unit;
46     }
47    
48     /**
49     * When listed, the attributes are listed according to their {@link #weight}
50     * (heavier => further down)
51     *
52     * @see #compareTo(AttributeMetadataImpl)
53     **/
54     protected int weight = 0;
55    
56     @Override
57     public double getWeight() {
58     return weight;
59     }
60    
61     @Override
62     public void setWeight(double weight) {
63     this.weight = new Double(weight).intValue();
64     }
65    
66     /**
67     * Will the end-user see this attribute?
68     */
69     @Override
70     public boolean isVisible() {
71     return visible;
72     }
73    
74     @Override
75     public void setDesc(final Translation desc) {
76     this.desc = desc;
77     }
78    
79     @Override
80     public Translation getDesc() {
81     return desc;
82     }
83    
84     /**
85     * The local name. E.g. the name of the DBF column as a {@link String}
86     */
87     @Override
88     public String getLocalName() {
89     return getName().getLocalPart();
90     }
91    
92     /**
93     * The fully qualified {@link Name} of the attribute, e.g.
94     * <code>org.bla.plo:blub</code>
95     */
96     @Override
97     public Name getName() {
98     return name;
99     }
100    
101     @Override
102     public HashSet<Object> getNodataValues() {
103     return nodataValues;
104     }
105    
106     /**
107     * The fully qualified Name of the attribute, e.g. org.bla.plo:blub
108     */
109     @Override
110     public void setLocalName(final String localName) {
111     setName(new NameImpl(localName));
112     }
113    
114     /**
115     * The fully qualified {@link Name} of the attribute, e.g.
116     * <code>org.bla.plo:blub</code>
117     */
118     @Override
119     public void setName(final Name name) {
120     this.name = name;
121     }
122    
123     public void addNodataValue(Object nodataValue) {
124     this.nodataValues.add(nodataValue);
125     }
126    
127     public void removeNodataValue(Object nodataValue) {
128     this.nodataValues.remove(nodataValue);
129     }
130    
131     @Override
132     public void setTitle(final Translation title) {
133     this.title = title;
134     }
135    
136     @Override
137     public void setUnit(final String unit) {
138     this.unit = unit;
139     }
140    
141     @Override
142     public void setVisible(final boolean visible) {
143     this.visible = visible;
144     }
145    
146     /**
147     * For nicer debugging
148     */
149     @Override
150     public String toString() {
151     StringBuffer sb = new StringBuffer();
152     if (name != null)
153     sb.append(name.toString() + " ");
154     sb.append("weight=" + weight + " ");
155     sb.append("title=" + getTitle().toString());
156     return sb.toString();
157     }
158    
159    
160     /**
161     * Takes any value object and checks it against the NODATA values. If the
162     * value equals a NODATA value, <code>null</code> is returned. Otherwise the
163     * same object is returned.
164     *
165     * Note: This method is called often.
166     */
167     @Override
168     public Object fiterNodata(final Object value) {
169     if (nodataValues.contains(value))
170     return null;
171     return value;
172     }
173    
174     /**
175     * @return a nicely formatted String containing all NODATA values. Strings
176     * are quoted so that any empty {@link String} can be seen.
177     */
178     @Override
179     public String getNoDataValuesFormatted() {
180     return StyledLayerUtil.formatNoDataValues(getNodataValues());
181     }
182     }

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