--- branches/2.0-RC2/src/skrueger/AttributeMetadata.java 2010/02/05 15:21:33 678
+++ trunk/src/skrueger/AttributeMetadataImpl.java 2010/05/22 01:24:46 862
@@ -25,7 +25,7 @@
*
* Contributors:
* Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Krüger - additional utility classes
+ * Stefan A. Tzeggai - additional utility classes
******************************************************************************/
package skrueger;
@@ -48,14 +48,11 @@
*
* @author Stefan Alfons Krüger
*/
-public class AttributeMetadata implements Copyable,
- Comparable {
-
- static private final Logger LOGGER = Logger
- .getLogger(AttributeMetadata.class);
+public class AttributeMetadataImpl extends AbstractAttributeMetadata implements
+ QualityQuantizable {
- /** Translation of the attribute's description **/
- protected Translation desc = new Translation();
+ static private final Logger LOGGER = Logger
+ .getLogger(AttributeMetadataImpl.class);
/**
* For numerical attributes the value can be transformed by VALUE*X+A when
@@ -69,51 +66,23 @@
**/
protected Double functionX = 1.;
- /** The Name of the attribute **/
- private Name name;
-
- /**
- * 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();
-
- /** Translation of the attribute's title **/
- protected Translation title = new Translation();
-
- /**
- * 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;
-
- /**
- * When listed, the attributes are listed according to their {@link #weight} (heavier
- * => further down)
- * @see #compareTo(AttributeMetadata)
- **/
- protected int weight = 0;
-
/** Only used for {@link Copyable#copy()} **/
- private AttributeMetadata() {
+ private AttributeMetadataImpl() {
}
- public AttributeMetadata(final AttributeDescriptor attDesc, final int weight,
- final List langs) {
- this(attDesc.getName(), langs);
+ public AttributeMetadataImpl(final AttributeDescriptor attDesc,
+ final int weight, final List langs) {
+ this( new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs);
setWeight(weight);
}
- public AttributeMetadata(final AttributeDescriptor attDesc, final List langs) {
- this(attDesc.getName(), langs);
+ public AttributeMetadataImpl(final AttributeDescriptor attDesc,
+ final List langs) {
+ this(new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs);
}
/**
- * Creates an {@link AttributeMetadata} object with the following
+ * Creates an {@link AttributeMetadataImpl} object with the following
* information
*
* @param colIdx
@@ -128,7 +97,7 @@
* @param unit
* {@link String} of the unit that the information is in
*/
- public AttributeMetadata(final Name name, final Boolean visible,
+ public AttributeMetadataImpl(final Name name, final Boolean visible,
final Translation title, final Translation desc, final String unit) {
this.setName(name);
@@ -137,10 +106,9 @@
this.visible = visible;
this.unit = unit;
}
-
/**
- * Creates an {@link AttributeMetadata} object with the following
+ * Creates an {@link AttributeMetadataImpl} object with the following
* information
*
* @param colIdx
@@ -151,31 +119,32 @@
* @param unit
* {@link String} of the unit that the information is in
*/
- public AttributeMetadata(final Name name, final Boolean visible, final String unit) {
+ public AttributeMetadataImpl(final Name name, final Boolean visible,
+ final String unit) {
this.setName(name);
this.visible = visible;
this.unit = unit;
}
/**
- * Creates a new visible {@link AttributeMetadata}
+ * Creates a new visible {@link AttributeMetadataImpl}
*/
- public AttributeMetadata(final Name name, final List langs) {
+ public AttributeMetadataImpl(final Name name, final List langs) {
this(name, true, new Translation(langs, name.getLocalPart()),
new Translation(), "");
}
/**
- * Creates a new visible {@link AttributeMetadata}
+ * Creates a new visible {@link AttributeMetadataImpl}
*/
- public AttributeMetadata(final Name name, final String defaultTitle,
+ public AttributeMetadataImpl(final Name name, final String defaultTitle,
final List langs) {
this(name, true, new Translation(langs, defaultTitle),
new Translation(), "");
}
/**
- * Creates an {@link AttributeMetadata} object with the following
+ * Creates an {@link AttributeMetadataImpl} object with the following
* information
*
* @param visible
@@ -187,24 +156,26 @@
* @param unit
* {@link String} of the unit that the information is in
*/
- public AttributeMetadata(final String localName, final Boolean visible,
+ public AttributeMetadataImpl(final String localName, final Boolean visible,
final Translation title, final Translation desc, final String unit) {
this(new NameImpl(localName), true, title, desc, "");
}
/**
- * Creates a new visible {@link AttributeMetadata} with default (no) values.
+ * Creates a new visible {@link AttributeMetadataImpl} with default (no)
+ * values.
*/
- public AttributeMetadata(final String localName, final List langs) {
+ public AttributeMetadataImpl(final String localName,
+ final List langs) {
this(localName, true, new Translation(langs, localName),
new Translation(), "");
}
/**
- * Creates a new visible {@link AttributeMetadata}
+ * Creates a new visible {@link AttributeMetadataImpl}
*/
- public AttributeMetadata(final String localName, final String defaultTitle,
- final List langs) {
+ public AttributeMetadataImpl(final String localName,
+ final String defaultTitle, final List langs) {
this(localName, true, new Translation(langs, defaultTitle),
new Translation(), "");
}
@@ -214,23 +185,24 @@
* further down.
*/
@Override
- public int compareTo(final AttributeMetadata atm2) {
- return new Integer(weight).compareTo(atm2.getWeight());
+ public int compareTo(final AttributeMetadataInterface atm2) {
+ return new Integer(weight).compareTo(new Double(atm2.getWeight())
+ .intValue());
}
/**
* @see Copyable inferface
*/
@Override
- public AttributeMetadata copy() {
- return copyTo(new AttributeMetadata());
+ public AttributeMetadataInterface copy() {
+ return copyTo(new AttributeMetadataImpl());
}
/**
* @see Copyable inferface
*/
@Override
- public AttributeMetadata copyTo(final AttributeMetadata amd) {
+ public AttributeMetadataInterface copyTo(final AttributeMetadataInterface amd) {
getTitle().copyTo(amd.getTitle());
getDesc().copyTo(amd.getDesc());
amd.setUnit(getUnit());
@@ -239,21 +211,21 @@
.getLocalPart()));
amd.setWeight(getWeight());
- amd.setFunctionX(getFunctionX());
- amd.setFunctionA(getFunctionA());
- amd.setNodataValues(getNodataValues());
+ if (amd instanceof AttributeMetadataImpl) {
+ AttributeMetadataImpl amd_ = (AttributeMetadataImpl) amd;
+
+ amd_.setFunctionX(getFunctionX());
+ amd_.setFunctionA(getFunctionA());
+ amd_.setNodataValues(getNodataValues());
+ }
return amd;
}
// only to be used by copyTo()
- private void setNodataValues(HashSet nodataValues2) {
- nodataValues = nodataValues2;
- }
-
- public Translation getDesc() {
- return desc;
+ private void setNodataValues(HashSet nodataValues_) {
+ nodataValues = nodataValues_;
}
public Double getFunctionA() {
@@ -265,28 +237,11 @@
}
/**
- * The local name. E.g. the name of the DBF column as a {@link String}
- */
- public String getLocalName() {
- return getName().getLocalPart();
- }
-
- /**
- * The fully qualified {@link Name} of the attribute, e.g. org.bla.plo:blub
- */
- public Name getName() {
- return name;
- }
-
- public HashSet getNodataValues() {
- return nodataValues;
- }
-
- /**
* @return a number between 0 (bad) and 1 (good) that is calculated from the
* amount of translation available. If this attribute is not
* {@link #visible}, it will return 1.
*/
+ @Override
public double getQuality(final List languages) {
if (!isVisible())
@@ -296,29 +251,6 @@
.qmTranslation(languages, getDesc()) * 1.) / 3.;
}
- public Translation getTitle() {
- return title;
- }
-
- public String getUnit() {
- return unit;
- }
-
- public int getWeight() {
- return weight;
- }
-
- /**
- * Will the end-user see this attribute?
- */
- public boolean isVisible() {
- return visible;
- }
-
- public void setDesc(final Translation desc) {
- this.desc = desc;
- }
-
public void setFunctionA(final Double functionA) {
this.functionA = functionA;
}
@@ -327,79 +259,5 @@
this.functionX = functionX;
}
- /**
- * The fully qualified Name of the attribute, e.g. org.bla.plo:blub
- */
- public void setLocalName(final String localName) {
- this.name = new NameImpl(localName);
- }
-
- /**
- * The fully qualified {@link Name} of the attribute, e.g. org.bla.plo:blub
- */
- 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);
- }
-
- public void setTitle(final Translation title) {
- this.title = title;
- }
-
- public void setUnit(final String unit) {
- this.unit = unit;
- }
-
- public void setVisible(final boolean visible) {
- this.visible = visible;
- }
-
- /**
- * 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;
-
- this.visible = visible;
- }
-
- 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());
- 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;
- }
}