/[schmitzm]/branches/2.0-RC1/src/skrueger/AttributeMetadata.java
ViewVC logotype

Diff of /branches/2.0-RC1/src/skrueger/AttributeMetadata.java

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

revision 533 by alfonx, Thu Nov 19 17:27:01 2009 UTC revision 534 by alfonx, Fri Nov 20 10:28:01 2009 UTC
# Line 50  import skrueger.i8n.Translation; Line 50  import skrueger.i8n.Translation;
50   */   */
51  public class AttributeMetadata implements Copyable<AttributeMetadata>,  public class AttributeMetadata implements Copyable<AttributeMetadata>,
52                  Comparable<AttributeMetadata> {                  Comparable<AttributeMetadata> {
53            
54          static private final Logger LOGGER = Logger          static private final Logger LOGGER = Logger
55                          .getLogger(AttributeMetadata.class);                          .getLogger(AttributeMetadata.class);
56    
         // public class WeightComparator implements Comparator<AttributeDescriptor>  
         // {  
         //  
         // @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();  
   
57          /** Translation of the attribute's description **/          /** Translation of the attribute's description **/
58          protected Translation desc = new Translation();          protected Translation desc = new Translation();
59    
60          /** Is the attribute visible to the user or ignored where possible **/          /**
61          protected boolean visible = true;           * For numerical attributes the value can be transformed by VALUE*X+A when
62             * presented on screen. TODO not implemented yet
63             **/
64            protected Double functionA = 0.;
65    
66          /**          /**
67           * The unit append to all visualizations of values of this attribute (is not           * For numerical attributes the value can be transformed by VALUE*X+A when
68           * null)           * presented on screen. TODO not implemented yet
69           **/           **/
70          protected String unit = "";          protected Double functionX = 1.;
71    
72          /** The Name of the attribute **/          /** The Name of the attribute **/
73          private Name name;          private Name name;
74    
         public int getWeight() {  
                 return weight;  
         }  
   
         public void setWeight(int weight) {  
                 this.weight = weight;  
         }  
   
         public List<Object> getNodataValues() {  
                 return nodataValues;  
         }  
   
         public void setNodataValues(List<Object> 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;  
   
75          /**          /**
76           * Allows to define general NODATA values for an attribute. e.g. -9999 can           * Allows to define general NODATA values for an attribute. e.g. -9999 can
77           * be set and will always be interpreted as NULL internally and will usually           * be set and will always be interpreted as NULL internally and will usually
78           * be ignored.           * be ignored. TODO not implemented yet
79           **/           **/
80          protected List<Object> nodataValues = new ArrayList<Object>();          protected List<Object> nodataValues = new ArrayList<Object>();
81    
82            /** Translation of the attribute's title **/
83            protected Translation title = new Translation();
84    
85          /**          /**
86           * For numerical attributes the value can be transformed by VALUE*X+A when           * The unit append to all visualizations of values of this attribute (is not
87           * presented on screen           * null)
88           **/           **/
89          protected Double functionX = 1.;          protected String unit = "";
90    
91            /** Is the attribute visible to the user or ignored where possible **/
92            protected boolean visible = true;
93    
94          /**          /**
95           * For numerical attributes the value can be transformed by VALUE*X+A when           * When listed, the attributes are listed according to their {@link #weight} (heavier
96           * presented on screen           * => further down)
97             * @see #compareTo(AttributeMetadata)
98           **/           **/
99          protected Double functionA = 0.;          protected int weight = 0;
100    
101            /** Only used for {@link Copyable<AttributeMetaData>#copy()} **/
102            private AttributeMetadata() {
103            }
104    
105            public AttributeMetadata(final AttributeDescriptor attDesc, final int weight,
106                            final List<String> langs) {
107                    this(attDesc.getName(), langs);
108                    setWeight(weight);
109            }
110    
111            public AttributeMetadata(final AttributeDescriptor attDesc, final List<String> langs) {
112                    this(attDesc.getName(), langs);
113            }
114    
115          /**          /**
116           * Creates an {@link AttributeMetadata} object with the following           * Creates an {@link AttributeMetadata} object with the following
# Line 165  public class AttributeMetadata implement Line 134  public class AttributeMetadata implement
134                  this.setName(name);                  this.setName(name);
135                  this.title = title;                  this.title = title;
136                  this.desc = desc;                  this.desc = desc;
137    //
138                  // The THE_GEOM and shall never be visible!  //              // The THE_GEOM and shall never be visible!
139                  if (name.getLocalPart().equalsIgnoreCase("the_geom"))  //              if (name.getLocalPart().equalsIgnoreCase("the_geom"))
140                          this.visible = false;  //                      this.visible = false;
141                  else  //              else
142                          this.visible = visible;  //                      this.visible = visible;
143    
144                  this.unit = unit;                  this.unit = unit;
145          }          }
146    
147          /**          /**
148             * Creates a new visible {@link AttributeMetadata}
149             */
150            public AttributeMetadata(final Name name, final List<String> langs) {
151                    this(name, true, new Translation(langs, name.getLocalPart()),
152                                    new Translation(), "");
153            }
154    
155            /**
156             * Creates a new visible {@link AttributeMetadata}
157             */
158            public AttributeMetadata(final Name name, final String defaultTitle,
159                            final List<String> langs) {
160                    this(name, true, new Translation(langs, defaultTitle),
161                                    new Translation(), "");
162            }
163    
164            /**
165           * Creates an {@link AttributeMetadata} object with the following           * Creates an {@link AttributeMetadata} object with the following
166           * information           * information
167           *           *
# Line 196  public class AttributeMetadata implement Line 182  public class AttributeMetadata implement
182          /**          /**
183           * Creates a new visible {@link AttributeMetadata} with default (no) values.           * Creates a new visible {@link AttributeMetadata} with default (no) values.
184           */           */
185          public AttributeMetadata(final String localName, final String defaultTitle, List<String> langs) {          public AttributeMetadata(final String localName, final List<String> langs) {
186                  this(localName, true, new Translation(langs, defaultTitle), new Translation(),                  this(localName, true, new Translation(langs, localName),
187                                  "");                                  new Translation(), "");
188          }          }
189    
190          /**          /**
191           * Creates a new visible {@link AttributeMetadata} with default (no) values.           * Creates a new visible {@link AttributeMetadata}
192           */           */
193          public AttributeMetadata(final Name name, final String defaultTitle, List<String> langs) {          public AttributeMetadata(final String localName, final String defaultTitle,
194                  this(name, true, new Translation(langs, defaultTitle), new Translation(), "");                          final List<String> langs) {
195                    this(localName, true, new Translation(langs, defaultTitle),
196                                    new Translation(), "");
197          }          }
198    
199          /**          /**
200           * Creates a new visible {@link AttributeMetadata} with default (no) values.           * Orders the attributes according to their {@link #weight}. Heavier =>
201             * further down.
202           */           */
203          public AttributeMetadata(final Name name, List<String> langs) {          @Override
204                  this(name, true, new Translation(langs, name.getLocalPart()),          public int compareTo(final AttributeMetadata atm2) {
205                                  new Translation(), "");                  return new Integer(weight).compareTo(atm2.getWeight());
206          }          }
207    
208          /**          /**
209           * Creates a new visible {@link AttributeMetadata} with default (no) values.           * @see Copyable inferface
210           */           */
211          public AttributeMetadata(final String localName, List<String> langs) {          @Override
212                  this(localName, true, new Translation(langs, localName), new Translation(), "");          public AttributeMetadata copy() {
213                    return copyTo(new AttributeMetadata());
214          }          }
215    
216          /** Only used for {@link Copyable<AttributeMetaData>#copy()} **/          /**
217          private AttributeMetadata() {           * @see Copyable inferface
218          }           */
219            @Override
220            public AttributeMetadata copyTo(final AttributeMetadata amd) {
221                    getTitle().copyTo(amd.getTitle());
222                    getDesc().copyTo(amd.getDesc());
223                    amd.setUnit(getUnit());
224                    amd.setVisible(isVisible());
225                    amd.setName(new NameImpl(getName().getNamespaceURI(), getName()
226                                    .getLocalPart()));
227    
228          public AttributeMetadata(AttributeDescriptor attDesc, List<String> langs) {                  amd.setWeight(getWeight());
229                  this(attDesc.getName(), langs);                  amd.setFunctionX(getFunctionX());
230                    amd.setFunctionA(getFunctionA());
231    
232                    for (final Object nodataValue : getNodataValues()) {
233                            amd.getNodataValues().add(nodataValue);
234                    }
235    
236                    return amd;
237          }          }
238    
239          public AttributeMetadata(AttributeDescriptor attDesc, int weight, List<String> langs) {          public Translation getDesc() {
240                  this(attDesc.getName(), langs);                  return desc;
                 setWeight(weight);  
241          }          }
242    
243          public boolean isVisible() {          public Double getFunctionA() {
244                  return visible;                  return functionA;
245          }          }
246    
247          public void setVisible(final Boolean visible) {          public Double getFunctionX() {
248                    return functionX;
249            }
250    
251                  // The THE_GEOM and shall never be visible! // TODO MAKE BETTER          /**
252                  if (name.getLocalPart().equalsIgnoreCase("the_geom"))           * The local name. E.g. the name of the DBF column as a {@link String}
253                          this.visible = false;           */
254                  else          public String getLocalName() {
255                          this.visible = visible;                  return getName().getLocalPart();
                   
                 this.visible = visible;  
256          }          }
257    
258          public Translation getTitle() {          /**
259                  return title;           * The fully qualified {@link Name} of the attribute, e.g. <code>org.bla.plo:blub</code>
260             */
261            public Name getName() {
262                    return name;
263          }          }
264    
265          public void setTitle(final Translation title) {          public List<Object> getNodataValues() {
266                  this.title = title;                  return nodataValues;
267          }          }
268    
269          public Translation getDesc() {          /**
270                  return desc;           * @return a number between 0 (bad) and 1 (good) that is calculated from the
271             *         amount of translation available. If this attribute is not
272             *         {@link #visible}, it will return 1.
273             */
274            public double getQuality(final List<String> languages) {
275    
276                    if (!isVisible())
277                            return 1.;
278    
279                    return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil
280                                    .qmTranslation(languages, getDesc()) * 1.) / 3.;
281          }          }
282    
283          public void setDesc(final Translation desc) {          public Translation getTitle() {
284                  this.desc = desc;                  return title;
285          }          }
286    
287          public String getUnit() {          public String getUnit() {
288                  return unit;                  return unit;
289          }          }
290    
291          public void setUnit(final String unit) {          public int getWeight() {
292                  this.unit = unit;                  return weight;
293          }          }
294    
295          @Override          /**
296          public AttributeMetadata copyTo(AttributeMetadata amd) {           * Will the end-user see this attribute?
297                  getTitle().copyTo(amd.getTitle());           */
298                  getDesc().copyTo(amd.getDesc());          public boolean isVisible() {
299                  amd.setUnit(getUnit());                  return visible;
300                  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);  
                 }  
301    
302                  return amd;          public void setDesc(final Translation desc) {
303                    this.desc = desc;
304          }          }
305    
306          @Override          public void setFunctionA(final Double functionA) {
307          public AttributeMetadata copy() {                  this.functionA = functionA;
                 return copyTo(new AttributeMetadata());  
308          }          }
309    
310          /**          public void setFunctionX(final Double functionX) {
311           * The local Name. E.g. the name of the DBF column as a String                  this.functionX = functionX;
          */  
         public String getLocalName() {  
                 return getName().getLocalPart();  
312          }          }
313    
314          /**          /**
315           * The fully qualified Name of the attribute, e.g. org.bla.plo:blub           * The fully qualified Name of the attribute, e.g. org.bla.plo:blub
316           */           */
317          public Name getName() {          public void setLocalName(final String localName) {
318                  return name;                  this.name = new NameImpl(localName);
319          }          }
320    
321          /**          /**
322           * The fully qualified Name of the attribute, e.g. org.bla.plo:blub           * The fully qualified {@link Name} of the attribute, e.g. <code>org.bla.plo:blub</code>
323           */           */
324          public void setName(org.opengis.feature.type.Name name) {          public void setName(final Name name) {
325                  this.name = name;                  this.name = name;
326          }          }
327    
328          /**          public void setNodataValues(final List<Object> nodataValues) {
329           * The fully qualified Name of the attribute, e.g. org.bla.plo:blub                  this.nodataValues = nodataValues;
330           */          }
331          public void setLocalName(String localName) {  
332                  this.name = new NameImpl(localName);          public void setTitle(final Translation title) {
333                    this.title = title;
334            }
335    
336            public void setUnit(final String unit) {
337                    this.unit = unit;
338            }
339    
340            public void setVisible(final boolean visible) {
341                    this.visible = visible;
342          }          }
343    
344          /**          /**
345           * Orders the Attributes according to their weight. Heavier => further down.           * Shall the end-user see this attribute?
346             * @param visible
347           */           */
348          @Override          public void setVisible(final Boolean visible) {
349          public int compareTo(AttributeMetadata atm2) {  //              // The THE_GEOM and shall never be visible!
350                  // Double double1 = new Double(1./weight);  //              if (name.getLocalPart().equalsIgnoreCase("the_geom"))
351                  // double double2 = 1./atm2.getWeight();  //                      this.visible = false;
352                  return new Integer(weight).compareTo(atm2.getWeight());  //              else
353    //                      this.visible = visible;
354    
355                    this.visible = visible;
356          }          }
357    
358            public void setWeight(final int weight) {
359                    this.weight = weight;
360            }
361            
362          /**          /**
363           * @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
364           */           */
365          public double getQuality(List<String> languages) {          @Override
366                  return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil          public String toString() {
367                                  .qmTranslation(languages, getDesc()) * 1.) / 3.;                  StringBuffer sb = new StringBuffer();
368                    if (name != null) sb.append(name.toString()+" ");
369                    sb.append("weight="+weight+" ");
370                    sb.append("title="+getTitle().toString());
371                    return sb.toString();
372          }          }
373  }  }

Legend:
Removed from v.533  
changed lines
  Added in v.534

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26