--- branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java 2009/11/19 17:27:01 533 +++ branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java 2009/11/20 10:28:01 534 @@ -50,98 +50,67 @@ */ public class AttributeMetadata implements Copyable, Comparable { + static private final Logger LOGGER = Logger .getLogger(AttributeMetadata.class); - // public class WeightComparator implements Comparator - // { - // - // @Override - // public int compare(AttributeDescriptor o1, AttributeDescriptor o2) { - // // TODO Auto-generated method stub - // return 0; - // } - // - // }; - - /** Translation of the attribute's title **/ - protected Translation title = new Translation(); - /** Translation of the attribute's description **/ protected Translation desc = new Translation(); - /** Is the attribute visible to the user or ignored where possible **/ - protected boolean visible = true; + /** + * For numerical attributes the value can be transformed by VALUE*X+A when + * presented on screen. TODO not implemented yet + **/ + protected Double functionA = 0.; /** - * The unit append to all visualizations of values of this attribute (is not - * null) + * For numerical attributes the value can be transformed by VALUE*X+A when + * presented on screen. TODO not implemented yet **/ - protected String unit = ""; + protected Double functionX = 1.; /** The Name of the attribute **/ private Name name; - public int getWeight() { - return weight; - } - - public void setWeight(int weight) { - this.weight = weight; - } - - public List getNodataValues() { - return nodataValues; - } - - public void setNodataValues(List nodataValues) { - this.nodataValues = nodataValues; - } - - public Double getFunctionX() { - return functionX; - } - - public void setFunctionX(Double functionX) { - this.functionX = functionX; - } - - public Double getFunctionA() { - return functionA; - } - - public void setFunctionA(Double functionA) { - this.functionA = functionA; - } - - public void setVisible(boolean visible) { - this.visible = visible; - } - - /** - * When listed, the attributes are listed according to their weight (heavier - * => further down) - **/ - protected int weight = 0; - /** * 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. + * be ignored. TODO not implemented yet **/ protected List nodataValues = new ArrayList(); + /** Translation of the attribute's title **/ + protected Translation title = new Translation(); + /** - * For numerical attributes the value can be transformed by VALUE*X+A when - * presented on screen + * The unit append to all visualizations of values of this attribute (is not + * null) **/ - protected Double functionX = 1.; + protected String unit = ""; + + /** Is the attribute visible to the user or ignored where possible **/ + protected boolean visible = true; /** - * For numerical attributes the value can be transformed by VALUE*X+A when - * presented on screen + * When listed, the attributes are listed according to their {@link #weight} (heavier + * => further down) + * @see #compareTo(AttributeMetadata) **/ - protected Double functionA = 0.; + protected int weight = 0; + + /** Only used for {@link Copyable#copy()} **/ + private AttributeMetadata() { + } + + 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) { + this(attDesc.getName(), langs); + } /** * Creates an {@link AttributeMetadata} object with the following @@ -165,17 +134,34 @@ this.setName(name); this.title = title; this.desc = desc; - - // 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.unit = unit; } /** + * Creates a new visible {@link AttributeMetadata} + */ + public AttributeMetadata(final Name name, final List langs) { + this(name, true, new Translation(langs, name.getLocalPart()), + new Translation(), ""); + } + + /** + * Creates a new visible {@link AttributeMetadata} + */ + public AttributeMetadata(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 * information * @@ -196,153 +182,192 @@ /** * Creates a new visible {@link AttributeMetadata} with default (no) values. */ - public AttributeMetadata(final String localName, final String defaultTitle, List langs) { - this(localName, true, new Translation(langs, defaultTitle), new Translation(), - ""); + public AttributeMetadata(final String localName, final List langs) { + this(localName, true, new Translation(langs, localName), + new Translation(), ""); } /** - * Creates a new visible {@link AttributeMetadata} with default (no) values. + * Creates a new visible {@link AttributeMetadata} */ - public AttributeMetadata(final Name name, final String defaultTitle, List langs) { - this(name, true, new Translation(langs, defaultTitle), new Translation(), ""); + public AttributeMetadata(final String localName, final String defaultTitle, + final List langs) { + this(localName, true, new Translation(langs, defaultTitle), + new Translation(), ""); } /** - * Creates a new visible {@link AttributeMetadata} with default (no) values. + * Orders the attributes according to their {@link #weight}. Heavier => + * further down. */ - public AttributeMetadata(final Name name, List langs) { - this(name, true, new Translation(langs, name.getLocalPart()), - new Translation(), ""); + @Override + public int compareTo(final AttributeMetadata atm2) { + return new Integer(weight).compareTo(atm2.getWeight()); } /** - * Creates a new visible {@link AttributeMetadata} with default (no) values. + * @see Copyable inferface */ - public AttributeMetadata(final String localName, List langs) { - this(localName, true, new Translation(langs, localName), new Translation(), ""); + @Override + public AttributeMetadata copy() { + return copyTo(new AttributeMetadata()); } - /** Only used for {@link Copyable#copy()} **/ - private AttributeMetadata() { - } + /** + * @see Copyable inferface + */ + @Override + public AttributeMetadata copyTo(final AttributeMetadata amd) { + getTitle().copyTo(amd.getTitle()); + getDesc().copyTo(amd.getDesc()); + amd.setUnit(getUnit()); + amd.setVisible(isVisible()); + amd.setName(new NameImpl(getName().getNamespaceURI(), getName() + .getLocalPart())); - public AttributeMetadata(AttributeDescriptor attDesc, List langs) { - this(attDesc.getName(), langs); + amd.setWeight(getWeight()); + amd.setFunctionX(getFunctionX()); + amd.setFunctionA(getFunctionA()); + + for (final Object nodataValue : getNodataValues()) { + amd.getNodataValues().add(nodataValue); + } + + return amd; } - public AttributeMetadata(AttributeDescriptor attDesc, int weight, List langs) { - this(attDesc.getName(), langs); - setWeight(weight); + public Translation getDesc() { + return desc; } - public boolean isVisible() { - return visible; + public Double getFunctionA() { + return functionA; } - public void setVisible(final Boolean visible) { + public Double getFunctionX() { + return functionX; + } - // The THE_GEOM and shall never be visible! // TODO MAKE BETTER - if (name.getLocalPart().equalsIgnoreCase("the_geom")) - this.visible = false; - else - this.visible = visible; - - this.visible = visible; + /** + * The local name. E.g. the name of the DBF column as a {@link String} + */ + public String getLocalName() { + return getName().getLocalPart(); } - public Translation getTitle() { - return title; + /** + * The fully qualified {@link Name} of the attribute, e.g. org.bla.plo:blub + */ + public Name getName() { + return name; } - public void setTitle(final Translation title) { - this.title = title; + public List getNodataValues() { + return nodataValues; } - public Translation getDesc() { - return desc; + /** + * @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. + */ + public double getQuality(final List languages) { + + if (!isVisible()) + return 1.; + + return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil + .qmTranslation(languages, getDesc()) * 1.) / 3.; } - public void setDesc(final Translation desc) { - this.desc = desc; + public Translation getTitle() { + return title; } public String getUnit() { return unit; } - public void setUnit(final String unit) { - this.unit = unit; + public int getWeight() { + return weight; } - @Override - public AttributeMetadata copyTo(AttributeMetadata amd) { - getTitle().copyTo(amd.getTitle()); - getDesc().copyTo(amd.getDesc()); - amd.setUnit(getUnit()); - amd.setVisible(isVisible()); - amd.setName(new NameImpl(getName().getNamespaceURI(), getName() - .getLocalPart())); - - amd.setWeight(getWeight()); - amd.setFunctionX(getFunctionX()); - amd.setFunctionA(getFunctionA()); - - for (Object nodataValue : getNodataValues()) { - amd.getNodataValues().add(nodataValue); - } + /** + * Will the end-user see this attribute? + */ + public boolean isVisible() { + return visible; + } - return amd; + public void setDesc(final Translation desc) { + this.desc = desc; } - @Override - public AttributeMetadata copy() { - return copyTo(new AttributeMetadata()); + public void setFunctionA(final Double functionA) { + this.functionA = functionA; } - /** - * The local Name. E.g. the name of the DBF column as a String - */ - public String getLocalName() { - return getName().getLocalPart(); + public void setFunctionX(final Double functionX) { + this.functionX = functionX; } /** * The fully qualified Name of the attribute, e.g. org.bla.plo:blub */ - public Name getName() { - return name; + public void setLocalName(final String localName) { + this.name = new NameImpl(localName); } /** - * The fully qualified 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(org.opengis.feature.type.Name name) { + public void setName(final Name name) { this.name = name; } - /** - * The fully qualified Name of the attribute, e.g. org.bla.plo:blub - */ - public void setLocalName(String localName) { - this.name = new NameImpl(localName); + public void setNodataValues(final List nodataValues) { + this.nodataValues = nodataValues; + } + + 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; } /** - * Orders the Attributes according to their weight. Heavier => further down. + * Shall the end-user see this attribute? + * @param visible */ - @Override - public int compareTo(AttributeMetadata atm2) { - // Double double1 = new Double(1./weight); - // double double2 = 1./atm2.getWeight(); - return new Integer(weight).compareTo(atm2.getWeight()); + 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; + } + /** - * @return a number between 0 (bad) and 1 (good) that is calculated from the amount of translation available in the visible attributes + * For nicer debugging */ - public double getQuality(List languages) { - return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil - .qmTranslation(languages, getDesc()) * 1.) / 3.; + @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(); } }