/[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/2.0-RC2/src/skrueger/AttributeMetadata.java revision 678 by alfonx, Fri Feb 5 15:21:33 2010 UTC trunk/src/skrueger/AttributeMetadata.java revision 685 by alfonx, Wed Feb 10 15:04:02 2010 UTC
# Line 31  package skrueger; Line 31  package skrueger;
31    
32  import java.util.HashSet;  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. This overcomes the problem, that           * be ignored. This overcomes the problem, that
80           **/           **/
81          protected HashSet<Object> nodataValues = new HashSet<Object>();          protected HashSet<Object> nodataValues = new HashSet<Object>();
82    
# 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 137  public class AttributeMetadata implement Line 140  public class AttributeMetadata implement
140                  this.visible = visible;                  this.visible = visible;
141                  this.unit = unit;                  this.unit = unit;
142          }          }
           
143    
144          /**          /**
145           * Creates an {@link AttributeMetadata} object with the following           * Creates an {@link AttributeMetadata} object with the following
# Line 151  public class AttributeMetadata implement Line 153  public class AttributeMetadata implement
153           * @param unit           * @param unit
154           *            {@link String} of the unit that the information is in           *            {@link String} of the unit that the information is in
155           */           */
156          public AttributeMetadata(final Name name, final Boolean visible, final String unit) {          public AttributeMetadata(final Name name, final Boolean visible,
157                            final String unit) {
158                  this.setName(name);                  this.setName(name);
159                  this.visible = visible;                  this.visible = visible;
160                  this.unit = unit;                  this.unit = unit;
# Line 166  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 201  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 272  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;
# Line 335  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;
# Line 344  public class AttributeMetadata implement Line 349  public class AttributeMetadata implement
349          public void addNodataValue(Object nodataValue) {          public void addNodataValue(Object nodataValue) {
350                  this.nodataValues.add(nodataValue);                  this.nodataValues.add(nodataValue);
351          }          }
352            
353          public void removeNodataValue(Object nodataValue) {          public void removeNodataValue(Object nodataValue) {
354                  this.nodataValues.remove(nodataValue);                  this.nodataValues.remove(nodataValue);
355          }          }
# Line 363  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 378  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    
# Line 399  public class AttributeMetadata implement Line 406  public class AttributeMetadata implement
406           * Note: This method is called often.           * Note: This method is called often.
407           */           */
408          public Object fiterNodata(final Object value) {          public Object fiterNodata(final Object value) {
409                  if (nodataValues.contains(value)) return null;                  if (nodataValues.contains(value))
410                            return null;
411                  return value;                  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.678  
changed lines
  Added in v.685

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26