--- branches/2.0-RC2/src/skrueger/AttributeMetadata.java 2010/02/04 19:05:34 675 +++ branches/2.0-RC2/src/skrueger/AttributeMetadata.java 2010/02/09 22:08:26 681 @@ -31,6 +31,7 @@ import java.util.HashSet; import java.util.List; +import java.util.Set; import org.apache.log4j.Logger; import org.geotools.feature.NameImpl; @@ -50,7 +51,7 @@ */ public class AttributeMetadata implements Copyable, Comparable { - + static private final Logger LOGGER = Logger .getLogger(AttributeMetadata.class); @@ -75,9 +76,9 @@ /** * Allows to define general NODATA values for an attribute. e.g. -9999 can * be set and will always be interpreted as NULL internally and will usually - * be ignored. This overcomes the problem, that + * be ignored. This overcomes the problem, that **/ - protected final HashSet nodataValues = new HashSet(); + protected HashSet nodataValues = new HashSet(); /** Translation of the attribute's title **/ protected Translation title = new Translation(); @@ -92,8 +93,9 @@ protected boolean visible = true; /** - * When listed, the attributes are listed according to their {@link #weight} (heavier - * => further down) + * When listed, the attributes are listed according to their {@link #weight} + * (heavier => further down) + * * @see #compareTo(AttributeMetadata) **/ protected int weight = 0; @@ -102,13 +104,14 @@ private AttributeMetadata() { } - public AttributeMetadata(final AttributeDescriptor attDesc, final int weight, - final List langs) { + public AttributeMetadata(final AttributeDescriptor attDesc, + final int weight, final List langs) { this(attDesc.getName(), langs); setWeight(weight); } - public AttributeMetadata(final AttributeDescriptor attDesc, final List langs) { + public AttributeMetadata(final AttributeDescriptor attDesc, + final List langs) { this(attDesc.getName(), langs); } @@ -137,7 +140,6 @@ this.visible = visible; this.unit = unit; } - /** * Creates an {@link AttributeMetadata} object with the following @@ -151,7 +153,8 @@ * @param unit * {@link String} of the unit that the information is in */ - public AttributeMetadata(final Name name, final Boolean visible, final String unit) { + public AttributeMetadata(final Name name, final Boolean visible, + final String unit) { this.setName(name); this.visible = visible; this.unit = unit; @@ -166,7 +169,7 @@ } /** - * Creates a new visible {@link AttributeMetadata} + * Creates a new visible {@link AttributeMetadata} */ public AttributeMetadata(final Name name, final String defaultTitle, final List langs) { @@ -201,7 +204,7 @@ } /** - * Creates a new visible {@link AttributeMetadata} + * Creates a new visible {@link AttributeMetadata} */ public AttributeMetadata(final String localName, final String defaultTitle, final List langs) { @@ -242,13 +245,16 @@ amd.setFunctionX(getFunctionX()); amd.setFunctionA(getFunctionA()); - for (final Object nodataValue : getNodataValues()) { - amd.getNodataValues().add(nodataValue); - } + amd.setNodataValues(getNodataValues()); return amd; } + // only to be used by copyTo() + private void setNodataValues(HashSet nodataValues2) { + nodataValues = nodataValues2; + } + public Translation getDesc() { return desc; } @@ -269,7 +275,8 @@ } /** - * The fully qualified {@link Name} of the attribute, e.g. org.bla.plo:blub + * The fully qualified {@link Name} of the attribute, e.g. + * org.bla.plo:blub */ public Name getName() { return name; @@ -332,7 +339,8 @@ } /** - * The fully qualified {@link Name} of the attribute, e.g. org.bla.plo:blub + * The fully qualified {@link Name} of the attribute, e.g. + * org.bla.plo:blub */ public void setName(final Name name) { this.name = name; @@ -341,7 +349,7 @@ public void addNodataValue(Object nodataValue) { this.nodataValues.add(nodataValue); } - + public void removeNodataValue(Object nodataValue) { this.nodataValues.remove(nodataValue); } @@ -360,14 +368,15 @@ /** * Shall the end-user see this attribute? + * * @param visible */ public void setVisible(final Boolean visible) { -// // The THE_GEOM and shall never be visible! -// if (name.getLocalPart().equalsIgnoreCase("the_geom")) -// this.visible = false; -// else -// this.visible = visible; + // // The THE_GEOM and shall never be visible! + // if (name.getLocalPart().equalsIgnoreCase("the_geom")) + // this.visible = false; + // else + // this.visible = visible; this.visible = visible; } @@ -375,16 +384,17 @@ public void setWeight(final int weight) { this.weight = weight; } - + /** * For nicer debugging */ @Override public String toString() { StringBuffer sb = new StringBuffer(); - if (name != null) sb.append(name.toString()+" "); - sb.append("weight="+weight+" "); - sb.append("title="+getTitle().toString()); + if (name != null) + sb.append(name.toString() + " "); + sb.append("weight=" + weight + " "); + sb.append("title=" + getTitle().toString()); return sb.toString(); } @@ -396,7 +406,42 @@ * Note: This method is called often. */ public Object fiterNodata(final Object value) { - if (nodataValues.contains(value)) return null; + if (nodataValues.contains(value)) + return null; return value; } + + /** + * @return a nicely formatted String containing all NODATA values. Strings + * are quoted fo that the empty String can be seen. + */ + public String getNoDataValuesFormatted() { + return formatNoDataValues(getNodataValues()); + } + + /** + * @return a nicely formatted String containing all NODATA values. Strings + * are quoted fo that the empty String can be seen. + */ + public static String formatNoDataValues(Set list) { + String nicelyFormatted = ""; + if (list != null) { + if (list.size() == 0) + nicelyFormatted = ""; + else { + for (Object ndo : list) { + if (ndo instanceof String) + nicelyFormatted += "\"" + ndo + "\""; + else + nicelyFormatted += ndo.toString(); + + nicelyFormatted += ","; + } + // Remove the extra comma + nicelyFormatted = nicelyFormatted.substring(0, nicelyFormatted + .length() - 1); + } + } + return nicelyFormatted; + } }