--- branches/2.0-RC1/src/skrueger/AttributeMetadata.java 2009/12/09 14:15:53 604 +++ branches/2.0-RC2/src/skrueger/AttributeMetadata.java 2010/02/05 15:21:33 678 @@ -29,7 +29,7 @@ ******************************************************************************/ package skrueger; -import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import org.apache.log4j.Logger; @@ -75,9 +75,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 +137,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} @@ -223,13 +242,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; } @@ -256,7 +278,7 @@ return name; } - public List getNodataValues() { + public HashSet getNodataValues() { return nodataValues; } @@ -319,8 +341,12 @@ this.name = name; } - public void setNodataValues(final List nodataValues) { - this.nodataValues = nodataValues; + public void addNodataValue(Object nodataValue) { + this.nodataValues.add(nodataValue); + } + + public void removeNodataValue(Object nodataValue) { + this.nodataValues.remove(nodataValue); } public void setTitle(final Translation title) { @@ -364,4 +390,16 @@ sb.append("title="+getTitle().toString()); return sb.toString(); } + + /** + * Takes any value object and checks it against 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) { + if (nodataValues.contains(value)) return null; + return value; + } }