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

Diff of /trunk/src/skrueger/AttributeMetadataImpl.java

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

branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java revision 546 by alfonx, Sun Nov 22 18:56:40 2009 UTC trunk/src/skrueger/AttributeMetadata.java revision 685 by alfonx, Wed Feb 10 15:04:02 2010 UTC
# Line 29  Line 29 
29   ******************************************************************************/   ******************************************************************************/
30  package skrueger;  package skrueger;
31    
32  import java.util.ArrayList;  import java.util.HashSet;
33  import java.util.List;  import java.util.List;
34    import java.util.Set;
35    
36  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
37  import org.geotools.feature.NameImpl;  import org.geotools.feature.NameImpl;
# Line 50  import skrueger.i8n.Translation; Line 51  import skrueger.i8n.Translation;
51   */   */
52  public class AttributeMetadata implements Copyable<AttributeMetadata>,  public class AttributeMetadata implements Copyable<AttributeMetadata>,
53                  Comparable<AttributeMetadata> {                  Comparable<AttributeMetadata> {
54            
55          static private final Logger LOGGER = Logger          static private final Logger LOGGER = Logger
56                          .getLogger(AttributeMetadata.class);                          .getLogger(AttributeMetadata.class);
57    
# Line 75  public class AttributeMetadata implement Line 76  public class AttributeMetadata implement
76          /**          /**
77           * Allows to define general NODATA values for an attribute. e.g. -9999 can           * Allows to define general NODATA values for an attribute. e.g. -9999 can
78           * be set and will always be interpreted as NULL internally and will usually           * be set and will always be interpreted as NULL internally and will usually
79           * be ignored. TODO not implemented yet           * be ignored. This overcomes the problem, that
80           **/           **/
81          protected List<Object> nodataValues = new ArrayList<Object>();          protected HashSet<Object> nodataValues = new HashSet<Object>();
82    
83          /** Translation of the attribute's title **/          /** Translation of the attribute's title **/
84          protected Translation title = new Translation();          protected Translation title = new Translation();
# Line 92  public class AttributeMetadata implement Line 93  public class AttributeMetadata implement
93          protected boolean visible = true;          protected boolean visible = true;
94    
95          /**          /**
96           * When listed, the attributes are listed according to their {@link #weight} (heavier           * When listed, the attributes are listed according to their {@link #weight}
97           * => further down)           * (heavier => further down)
98             *
99           * @see #compareTo(AttributeMetadata)           * @see #compareTo(AttributeMetadata)
100           **/           **/
101          protected int weight = 0;          protected int weight = 0;
# Line 102  public class AttributeMetadata implement Line 104  public class AttributeMetadata implement
104          private AttributeMetadata() {          private AttributeMetadata() {
105          }          }
106    
107          public AttributeMetadata(final AttributeDescriptor attDesc, final int weight,          public AttributeMetadata(final AttributeDescriptor attDesc,
108                          final List<String> langs) {                          final int weight, final List<String> langs) {
109                  this(attDesc.getName(), langs);                  this(attDesc.getName(), langs);
110                  setWeight(weight);                  setWeight(weight);
111          }          }
112    
113          public AttributeMetadata(final AttributeDescriptor attDesc, final List<String> langs) {          public AttributeMetadata(final AttributeDescriptor attDesc,
114                            final List<String> langs) {
115                  this(attDesc.getName(), langs);                  this(attDesc.getName(), langs);
116          }          }
117    
# Line 139  public class AttributeMetadata implement Line 142  public class AttributeMetadata implement
142          }          }
143    
144          /**          /**
145             * Creates an {@link AttributeMetadata} object with the following
146             * information
147             *
148             * @param colIdx
149             *            The column index of this attribute in the underlying
150             *            table/dbf/etc...
151             * @param visible
152             *            Shall this attribute be displayed or hidden from the user?
153             * @param unit
154             *            {@link String} of the unit that the information is in
155             */
156            public AttributeMetadata(final Name name, final Boolean visible,
157                            final String unit) {
158                    this.setName(name);
159                    this.visible = visible;
160                    this.unit = unit;
161            }
162    
163            /**
164           * Creates a new visible {@link AttributeMetadata}           * Creates a new visible {@link AttributeMetadata}
165           */           */
166          public AttributeMetadata(final Name name, final List<String> langs) {          public AttributeMetadata(final Name name, final List<String> langs) {
# Line 147  public class AttributeMetadata implement Line 169  public class AttributeMetadata implement
169          }          }
170    
171          /**          /**
172           * Creates a new visible {@link AttributeMetadata}           * Creates a new visible {@link AttributeMetadata}
173           */           */
174          public AttributeMetadata(final Name name, final String defaultTitle,          public AttributeMetadata(final Name name, final String defaultTitle,
175                          final List<String> langs) {                          final List<String> langs) {
# Line 182  public class AttributeMetadata implement Line 204  public class AttributeMetadata implement
204          }          }
205    
206          /**          /**
207           * Creates a new visible {@link AttributeMetadata}           * Creates a new visible {@link AttributeMetadata}
208           */           */
209          public AttributeMetadata(final String localName, final String defaultTitle,          public AttributeMetadata(final String localName, final String defaultTitle,
210                          final List<String> langs) {                          final List<String> langs) {
# Line 223  public class AttributeMetadata implement Line 245  public class AttributeMetadata implement
245                  amd.setFunctionX(getFunctionX());                  amd.setFunctionX(getFunctionX());
246                  amd.setFunctionA(getFunctionA());                  amd.setFunctionA(getFunctionA());
247    
248                  for (final Object nodataValue : getNodataValues()) {                  amd.setNodataValues(getNodataValues());
                         amd.getNodataValues().add(nodataValue);  
                 }  
249    
250                  return amd;                  return amd;
251          }          }
252    
253            // only to be used by copyTo()
254            private void setNodataValues(HashSet<Object> nodataValues2) {
255                    nodataValues = nodataValues2;
256            }
257    
258          public Translation getDesc() {          public Translation getDesc() {
259                  return desc;                  return desc;
260          }          }
# Line 250  public class AttributeMetadata implement Line 275  public class AttributeMetadata implement
275          }          }
276    
277          /**          /**
278           * The fully qualified {@link Name} of the attribute, e.g. <code>org.bla.plo:blub</code>           * The fully qualified {@link Name} of the attribute, e.g.
279             * <code>org.bla.plo:blub</code>
280           */           */
281          public Name getName() {          public Name getName() {
282                  return name;                  return name;
283          }          }
284    
285          public List<Object> getNodataValues() {          public HashSet<Object> getNodataValues() {
286                  return nodataValues;                  return nodataValues;
287          }          }
288    
# Line 313  public class AttributeMetadata implement Line 339  public class AttributeMetadata implement
339          }          }
340    
341          /**          /**
342           * The fully qualified {@link Name} of the attribute, e.g. <code>org.bla.plo:blub</code>           * The fully qualified {@link Name} of the attribute, e.g.
343             * <code>org.bla.plo:blub</code>
344           */           */
345          public void setName(final Name name) {          public void setName(final Name name) {
346                  this.name = name;                  this.name = name;
347          }          }
348    
349          public void setNodataValues(final List<Object> nodataValues) {          public void addNodataValue(Object nodataValue) {
350                  this.nodataValues = nodataValues;                  this.nodataValues.add(nodataValue);
351            }
352    
353            public void removeNodataValue(Object nodataValue) {
354                    this.nodataValues.remove(nodataValue);
355          }          }
356    
357          public void setTitle(final Translation title) {          public void setTitle(final Translation title) {
# Line 337  public class AttributeMetadata implement Line 368  public class AttributeMetadata implement
368    
369          /**          /**
370           * Shall the end-user see this attribute?           * Shall the end-user see this attribute?
371             *
372           * @param visible           * @param visible
373           */           */
374          public void setVisible(final Boolean visible) {          public void setVisible(final Boolean visible) {
375  //              // The THE_GEOM and shall never be visible!                  // // The THE_GEOM and shall never be visible!
376  //              if (name.getLocalPart().equalsIgnoreCase("the_geom"))                  // if (name.getLocalPart().equalsIgnoreCase("the_geom"))
377  //                      this.visible = false;                  // this.visible = false;
378  //              else                  // else
379  //                      this.visible = visible;                  // this.visible = visible;
380    
381                  this.visible = visible;                  this.visible = visible;
382          }          }
# Line 352  public class AttributeMetadata implement Line 384  public class AttributeMetadata implement
384          public void setWeight(final int weight) {          public void setWeight(final int weight) {
385                  this.weight = weight;                  this.weight = weight;
386          }          }
387            
388          /**          /**
389           * For nicer debugging           * For nicer debugging
390           */           */
391          @Override          @Override
392          public String toString() {          public String toString() {
393                  StringBuffer sb = new StringBuffer();                  StringBuffer sb = new StringBuffer();
394                  if (name != null) sb.append(name.toString()+" ");                  if (name != null)
395                  sb.append("weight="+weight+" ");                          sb.append(name.toString() + " ");
396                  sb.append("title="+getTitle().toString());                  sb.append("weight=" + weight + " ");
397                    sb.append("title=" + getTitle().toString());
398                  return sb.toString();                  return sb.toString();
399          }          }
400    
401            /**
402             * Takes any value object and checks it against the NODATA values. If the
403             * value equals a NODATA value, <code>null</code> is returned. Otherwise the
404             * same object is returned.
405             *
406             * Note: This method is called often.
407             */
408            public Object fiterNodata(final Object value) {
409                    if (nodataValues.contains(value))
410                            return null;
411                    return value;
412            }
413    
414            /**
415             * @return a nicely formatted String containing all NODATA values. Strings
416             *         are quoted fo that the empty String can be seen.
417             */
418            public String getNoDataValuesFormatted() {
419                    return formatNoDataValues(getNodataValues());
420            }
421    
422            /**
423             * @return a nicely formatted String containing all NODATA values. Strings
424             *         are quoted fo that the empty String can be seen.
425             */
426            public static String formatNoDataValues(Set<Object> list) {
427                    String nicelyFormatted = "";
428                    if (list != null) {
429                            if (list.size() == 0)
430                                    nicelyFormatted = "";
431                            else {
432                                    for (Object ndo : list) {
433                                            if (ndo instanceof String)
434                                                    nicelyFormatted += "\"" + ndo + "\"";
435                                            else
436                                                    nicelyFormatted += ndo.toString();
437    
438                                            nicelyFormatted += ",";
439                                    }
440                                    // Remove the extra comma
441                                    nicelyFormatted = nicelyFormatted.substring(0, nicelyFormatted
442                                                    .length() - 1);
443                            }
444                    }
445                    return nicelyFormatted;
446            }
447  }  }

Legend:
Removed from v.546  
changed lines
  Added in v.685

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26