package skrueger; import java.util.HashSet; import org.geotools.feature.NameImpl; import org.opengis.feature.type.Name; import skrueger.geotools.StyledLayerUtil; import skrueger.i8n.Translation; public abstract class AbstractAttributeMetadata implements AttributeMetadataInterface { /** The Name of the attribute. This is the 'primary key' **/ protected Name name; /** {@link Translation}s of the attribute's title **/ protected Translation title = new Translation(); /** {@link Translation}s of the attribute's description **/ protected Translation desc = new Translation(); /** * 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 **/ protected HashSet nodataValues = new HashSet(); /** * The unit append to all visualizations of values of this attribute (is not * null) **/ protected String unit = ""; /** Is the attribute visible to the user or ignored where possible **/ protected boolean visible = true; @Override public Translation getTitle() { return title; } @Override public String getUnit() { return unit; } @Override public void setTitle(final String title) { this.title = new Translation(title); } @Override public void setDesc(final String desc) { this.desc = new Translation(desc); } /** * When listed, the attributes are listed according to their {@link #weight} * (heavier => further down) * * @see #compareTo(AttributeMetadataImpl) **/ protected int weight = 0; @Override public double getWeight() { return weight; } @Override public void setWeight(double weight) { this.weight = new Double(weight).intValue(); } /** * Will the end-user see this attribute? */ @Override public boolean isVisible() { return visible; } @Override public void setDesc(final Translation desc) { this.desc = desc; } @Override public Translation getDesc() { return desc; } /** * The local name. E.g. the name of the DBF column as a {@link String} */ @Override public String getLocalName() { return getName().getLocalPart(); } /** * The fully qualified {@link Name} of the attribute, e.g. * org.bla.plo:blub */ @Override public Name getName() { return name; } @Override public HashSet getNodataValues() { return nodataValues; } /** * The fully qualified Name of the attribute, e.g. org.bla.plo:blub */ @Override public void setLocalName(final String localName) { setName(new NameImpl(localName)); } /** * The fully qualified {@link Name} of the attribute, e.g. * org.bla.plo:blub */ @Override public void setName(final Name name) { this.name = name; } public void addNodataValue(Object nodataValue) { this.nodataValues.add(nodataValue); } public void removeNodataValue(Object nodataValue) { this.nodataValues.remove(nodataValue); } @Override public void setTitle(final Translation title) { this.title = title; } @Override public void setUnit(final String unit) { this.unit = unit; } @Override public void setVisible(final boolean visible) { this.visible = visible; } /** * 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()); 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. */ @Override public Object fiterNodata(final Object value) { if (nodataValues.contains(value)) return null; return value; } /** * @return a nicely formatted String containing all NODATA values. Strings * are quoted so that any empty {@link String} can be seen. */ @Override public String getNoDataValuesFormatted() { return StyledLayerUtil.formatNoDataValues(getNodataValues()); } }