/[schmitzm]/trunk/src/skrueger/AttributeMetadataImpl.java
ViewVC logotype

Diff of /trunk/src/skrueger/AttributeMetadataImpl.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

branches/2.0-RC2/src/skrueger/AttributeMetadata.java revision 681 by alfonx, Tue Feb 9 22:08:26 2010 UTC trunk/src/skrueger/AttributeMetadataImpl.java revision 862 by alfonx, Sat May 22 01:24:46 2010 UTC
# Line 25  Line 25 
25   *   *
26   * Contributors:   * Contributors:
27   *     Martin O. J. Schmitz - initial API and implementation   *     Martin O. J. Schmitz - initial API and implementation
28   *     Stefan A. Krüger - additional utility classes   *     Stefan A. Tzeggai - additional utility classes
29   ******************************************************************************/   ******************************************************************************/
30  package skrueger;  package skrueger;
31    
32  import java.util.HashSet;  import java.util.HashSet;
33  import java.util.List;  import java.util.List;
 import java.util.Set;  
34    
35  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
36  import org.geotools.feature.NameImpl;  import org.geotools.feature.NameImpl;
# Line 49  import skrueger.i8n.Translation; Line 48  import skrueger.i8n.Translation;
48   *   *
49   * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>   * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>
50   */   */
51  public class AttributeMetadata implements Copyable<AttributeMetadata>,  public class AttributeMetadataImpl extends AbstractAttributeMetadata implements
52                  Comparable<AttributeMetadata> {                  QualityQuantizable {
53    
54          static private final Logger LOGGER = Logger          static private final Logger LOGGER = Logger
55                          .getLogger(AttributeMetadata.class);                          .getLogger(AttributeMetadataImpl.class);
   
         /** Translation of the attribute's description **/  
         protected Translation desc = new Translation();  
56    
57          /**          /**
58           * For numerical attributes the value can be transformed by VALUE*X+A when           * For numerical attributes the value can be transformed by VALUE*X+A when
# Line 70  public class AttributeMetadata implement Line 66  public class AttributeMetadata implement
66           **/           **/
67          protected Double functionX = 1.;          protected Double functionX = 1.;
68    
         /** 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<Object> nodataValues = new HashSet<Object>();  
   
         /** 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;  
   
69          /** Only used for {@link Copyable<AttributeMetaData>#copy()} **/          /** Only used for {@link Copyable<AttributeMetaData>#copy()} **/
70          private AttributeMetadata() {          private AttributeMetadataImpl() {
71          }          }
72    
73          public AttributeMetadata(final AttributeDescriptor attDesc,          public AttributeMetadataImpl(final AttributeDescriptor attDesc,
74                          final int weight, final List<String> langs) {                          final int weight, final List<String> langs) {
75                  this(attDesc.getName(), langs);                  this( new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs);
76                  setWeight(weight);                  setWeight(weight);
77          }          }
78    
79          public AttributeMetadata(final AttributeDescriptor attDesc,          public AttributeMetadataImpl(final AttributeDescriptor attDesc,
80                          final List<String> langs) {                          final List<String> langs) {
81                  this(attDesc.getName(), langs);                  this(new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs);
82          }          }
83    
84          /**          /**
85           * Creates an {@link AttributeMetadata} object with the following           * Creates an {@link AttributeMetadataImpl} object with the following
86           * information           * information
87           *           *
88           * @param colIdx           * @param colIdx
# Line 131  public class AttributeMetadata implement Line 97  public class AttributeMetadata implement
97           * @param unit           * @param unit
98           *            {@link String} of the unit that the information is in           *            {@link String} of the unit that the information is in
99           */           */
100          public AttributeMetadata(final Name name, final Boolean visible,          public AttributeMetadataImpl(final Name name, final Boolean visible,
101                          final Translation title, final Translation desc, final String unit) {                          final Translation title, final Translation desc, final String unit) {
102    
103                  this.setName(name);                  this.setName(name);
# Line 142  public class AttributeMetadata implement Line 108  public class AttributeMetadata implement
108          }          }
109    
110          /**          /**
111           * Creates an {@link AttributeMetadata} object with the following           * Creates an {@link AttributeMetadataImpl} object with the following
112           * information           * information
113           *           *
114           * @param colIdx           * @param colIdx
# Line 153  public class AttributeMetadata implement Line 119  public class AttributeMetadata implement
119           * @param unit           * @param unit
120           *            {@link String} of the unit that the information is in           *            {@link String} of the unit that the information is in
121           */           */
122          public AttributeMetadata(final Name name, final Boolean visible,          public AttributeMetadataImpl(final Name name, final Boolean visible,
123                          final String unit) {                          final String unit) {
124                  this.setName(name);                  this.setName(name);
125                  this.visible = visible;                  this.visible = visible;
# Line 161  public class AttributeMetadata implement Line 127  public class AttributeMetadata implement
127          }          }
128    
129          /**          /**
130           * Creates a new visible {@link AttributeMetadata}           * Creates a new visible {@link AttributeMetadataImpl}
131           */           */
132          public AttributeMetadata(final Name name, final List<String> langs) {          public AttributeMetadataImpl(final Name name, final List<String> langs) {
133                  this(name, true, new Translation(langs, name.getLocalPart()),                  this(name, true, new Translation(langs, name.getLocalPart()),
134                                  new Translation(), "");                                  new Translation(), "");
135          }          }
136    
137          /**          /**
138           * Creates a new visible {@link AttributeMetadata}           * Creates a new visible {@link AttributeMetadataImpl}
139           */           */
140          public AttributeMetadata(final Name name, final String defaultTitle,          public AttributeMetadataImpl(final Name name, final String defaultTitle,
141                          final List<String> langs) {                          final List<String> langs) {
142                  this(name, true, new Translation(langs, defaultTitle),                  this(name, true, new Translation(langs, defaultTitle),
143                                  new Translation(), "");                                  new Translation(), "");
144          }          }
145    
146          /**          /**
147           * Creates an {@link AttributeMetadata} object with the following           * Creates an {@link AttributeMetadataImpl} object with the following
148           * information           * information
149           *           *
150           * @param visible           * @param visible
# Line 190  public class AttributeMetadata implement Line 156  public class AttributeMetadata implement
156           * @param unit           * @param unit
157           *            {@link String} of the unit that the information is in           *            {@link String} of the unit that the information is in
158           */           */
159          public AttributeMetadata(final String localName, final Boolean visible,          public AttributeMetadataImpl(final String localName, final Boolean visible,
160                          final Translation title, final Translation desc, final String unit) {                          final Translation title, final Translation desc, final String unit) {
161                  this(new NameImpl(localName), true, title, desc, "");                  this(new NameImpl(localName), true, title, desc, "");
162          }          }
163    
164          /**          /**
165           * Creates a new visible {@link AttributeMetadata} with default (no) values.           * Creates a new visible {@link AttributeMetadataImpl} with default (no)
166             * values.
167           */           */
168          public AttributeMetadata(final String localName, final List<String> langs) {          public AttributeMetadataImpl(final String localName,
169                            final List<String> langs) {
170                  this(localName, true, new Translation(langs, localName),                  this(localName, true, new Translation(langs, localName),
171                                  new Translation(), "");                                  new Translation(), "");
172          }          }
173    
174          /**          /**
175           * Creates a new visible {@link AttributeMetadata}           * Creates a new visible {@link AttributeMetadataImpl}
176           */           */
177          public AttributeMetadata(final String localName, final String defaultTitle,          public AttributeMetadataImpl(final String localName,
178                          final List<String> langs) {                          final String defaultTitle, final List<String> langs) {
179                  this(localName, true, new Translation(langs, defaultTitle),                  this(localName, true, new Translation(langs, defaultTitle),
180                                  new Translation(), "");                                  new Translation(), "");
181          }          }
# Line 217  public class AttributeMetadata implement Line 185  public class AttributeMetadata implement
185           * further down.           * further down.
186           */           */
187          @Override          @Override
188          public int compareTo(final AttributeMetadata atm2) {          public int compareTo(final AttributeMetadataInterface atm2) {
189                  return new Integer(weight).compareTo(atm2.getWeight());                  return new Integer(weight).compareTo(new Double(atm2.getWeight())
190                                    .intValue());
191          }          }
192    
193          /**          /**
194           * @see Copyable inferface           * @see Copyable inferface
195           */           */
196          @Override          @Override
197          public AttributeMetadata copy() {          public AttributeMetadataInterface copy() {
198                  return copyTo(new AttributeMetadata());                  return copyTo(new AttributeMetadataImpl());
199          }          }
200    
201          /**          /**
202           * @see Copyable inferface           * @see Copyable inferface
203           */           */
204          @Override          @Override
205          public AttributeMetadata copyTo(final AttributeMetadata amd) {          public AttributeMetadataInterface copyTo(final AttributeMetadataInterface amd) {
206                  getTitle().copyTo(amd.getTitle());                  getTitle().copyTo(amd.getTitle());
207                  getDesc().copyTo(amd.getDesc());                  getDesc().copyTo(amd.getDesc());
208                  amd.setUnit(getUnit());                  amd.setUnit(getUnit());
# Line 242  public class AttributeMetadata implement Line 211  public class AttributeMetadata implement
211                                  .getLocalPart()));                                  .getLocalPart()));
212    
213                  amd.setWeight(getWeight());                  amd.setWeight(getWeight());
                 amd.setFunctionX(getFunctionX());  
                 amd.setFunctionA(getFunctionA());  
214    
215                  amd.setNodataValues(getNodataValues());                  if (amd instanceof AttributeMetadataImpl) {
216                            AttributeMetadataImpl amd_ = (AttributeMetadataImpl) amd;
217    
218                            amd_.setFunctionX(getFunctionX());
219                            amd_.setFunctionA(getFunctionA());
220                            amd_.setNodataValues(getNodataValues());
221                    }
222    
223                  return amd;                  return amd;
224          }          }
225    
226          // only to be used by copyTo()          // only to be used by copyTo()
227          private void setNodataValues(HashSet<Object> nodataValues2) {          private void setNodataValues(HashSet<Object> nodataValues_) {
228                  nodataValues = nodataValues2;                  nodataValues = nodataValues_;
         }  
   
         public Translation getDesc() {  
                 return desc;  
229          }          }
230    
231          public Double getFunctionA() {          public Double getFunctionA() {
# Line 268  public class AttributeMetadata implement Line 237  public class AttributeMetadata implement
237          }          }
238    
239          /**          /**
          * 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.  
          * <code>org.bla.plo:blub</code>  
          */  
         public Name getName() {  
                 return name;  
         }  
   
         public HashSet<Object> getNodataValues() {  
                 return nodataValues;  
         }  
   
         /**  
240           * @return a number between 0 (bad) and 1 (good) that is calculated from the           * @return a number between 0 (bad) and 1 (good) that is calculated from the
241           *         amount of translation available. If this attribute is not           *         amount of translation available. If this attribute is not
242           *         {@link #visible}, it will return 1.           *         {@link #visible}, it will return 1.
243           */           */
244            @Override
245          public double getQuality(final List<String> languages) {          public double getQuality(final List<String> languages) {
246    
247                  if (!isVisible())                  if (!isVisible())
# Line 300  public class AttributeMetadata implement Line 251  public class AttributeMetadata implement
251                                  .qmTranslation(languages, getDesc()) * 1.) / 3.;                                  .qmTranslation(languages, getDesc()) * 1.) / 3.;
252          }          }
253    
         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;  
         }  
   
254          public void setFunctionA(final Double functionA) {          public void setFunctionA(final Double functionA) {
255                  this.functionA = functionA;                  this.functionA = functionA;
256          }          }
# Line 331  public class AttributeMetadata implement Line 259  public class AttributeMetadata implement
259                  this.functionX = functionX;                  this.functionX = functionX;
260          }          }
261    
         /**  
          * The fully qualified Name of the attribute, e.g. org.bla.plo:blub  
          */  
         public void setLocalName(final String localName) {  
                 this.name = new NameImpl(localName);  
         }  
262    
         /**  
          * The fully qualified {@link Name} of the attribute, e.g.  
          * <code>org.bla.plo:blub</code>  
          */  
         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, <code>null</code> 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;  
         }  
   
         /**  
          * @return a nicely formatted String containing all NODATA values. Strings  
          *         are quoted fo that the empty String can be seen.  
          */  
         public String getNoDataValuesFormatted() {  
                 return formatNoDataValues(getNodataValues());  
         }  
   
         /**  
          * @return a nicely formatted String containing all NODATA values. Strings  
          *         are quoted fo that the empty String can be seen.  
          */  
         public static String formatNoDataValues(Set<Object> list) {  
                 String nicelyFormatted = "";  
                 if (list != null) {  
                         if (list.size() == 0)  
                                 nicelyFormatted = "";  
                         else {  
                                 for (Object ndo : list) {  
                                         if (ndo instanceof String)  
                                                 nicelyFormatted += "\"" + ndo + "\"";  
                                         else  
                                                 nicelyFormatted += ndo.toString();  
   
                                         nicelyFormatted += ",";  
                                 }  
                                 // Remove the extra comma  
                                 nicelyFormatted = nicelyFormatted.substring(0, nicelyFormatted  
                                                 .length() - 1);  
                         }  
                 }  
                 return nicelyFormatted;  
         }  
263  }  }

Legend:
Removed from v.681  
changed lines
  Added in v.862

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26