--- branches/2.0-RC2/src/skrueger/AttributeMetadata.java 2010/01/28 10:06:05 621 +++ branches/2.0-RC2/src/skrueger/AttributeMetadata.java 2010/02/03 15:32:21 658 @@ -30,10 +30,12 @@ package skrueger; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import org.apache.log4j.Logger; import org.geotools.feature.NameImpl; +import org.geotools.feature.Feature.NULL; import org.opengis.feature.type.AttributeDescriptor; import org.opengis.feature.type.Name; @@ -75,9 +77,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. TODO not implemented yet + * be ignored. This overcomes the problem, that **/ - protected List nodataValues = new ArrayList(); + protected HashSet nodataValues = new HashSet(); /** Translation of the attribute's title **/ protected Translation title = new Translation(); @@ -137,6 +139,25 @@ this.visible = visible; this.unit = unit; } + + + /** + * Creates an {@link AttributeMetadata} object with the following + * information + * + * @param colIdx + * The column index of this attribute in the underlying + * table/dbf/etc... + * @param visible + * Shall this attribute be displayed or hidden from the user? + * @param unit + * {@link String} of the unit that the information is in + */ + public AttributeMetadata(final Name name, final Boolean visible, final String unit) { + this.setName(name); + this.visible = visible; + this.unit = unit; + } /** * Creates a new visible {@link AttributeMetadata} @@ -256,7 +277,7 @@ return name; } - public List getNodataValues() { + public HashSet getNodataValues() { return nodataValues; } @@ -319,7 +340,7 @@ this.name = name; } - public void setNodataValues(final List nodataValues) { + public void setNodataValues(final HashSet nodataValues) { this.nodataValues = nodataValues; } @@ -364,4 +385,21 @@ sb.append("title="+getTitle().toString()); return sb.toString(); } + + /** + * Takes any value object and checks it againsts the NODATA values. If the + * value equals a NODATA value, null is returned. Otherwise the + * same object is returned. + * + * Note: This method is called often. + */ + public Object fiterNodata(final Object value) { + + // contains.. hash + for (final Object nodataValue : getNodataValues()) { + if (nodataValue.equals(value)) + return null; + } + return value; + } }