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.ArrayList; |
import java.util.HashSet; |
33 |
import java.util.List; |
import java.util.List; |
34 |
|
|
35 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
48 |
* |
* |
49 |
* @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
* @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
50 |
*/ |
*/ |
51 |
public class AttributeMetadata implements Copyable<AttributeMetadata>, |
public class AttributeMetadataImpl extends AbstractAttributeMetadata implements |
52 |
Comparable<AttributeMetadata> { |
QualityQuantizable { |
|
static private final Logger LOGGER = Logger |
|
|
.getLogger(AttributeMetadata.class); |
|
|
|
|
|
// 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(); |
|
|
|
|
|
/** Translation of the attribute's description **/ |
|
|
protected Translation desc = new Translation(); |
|
53 |
|
|
54 |
/** Is the attribute visible to the user or ignored where possible **/ |
static private final Logger LOGGER = Logger |
55 |
protected boolean visible = true; |
.getLogger(AttributeMetadataImpl.class); |
56 |
|
|
57 |
/** |
/** |
58 |
* 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 |
59 |
* null) |
* presented on screen. TODO not implemented yet |
60 |
**/ |
**/ |
61 |
protected String unit = ""; |
protected Double functionA = 0.; |
|
|
|
|
/** The Name of the attribute **/ |
|
|
private Name name; |
|
|
|
|
|
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; |
|
|
} |
|
62 |
|
|
63 |
public void setFunctionX(Double functionX) { |
/** |
64 |
this.functionX = functionX; |
* For numerical attributes the value can be transformed by VALUE*X+A when |
65 |
} |
* presented on screen. TODO not implemented yet |
66 |
|
**/ |
67 |
|
protected Double functionX = 1.; |
68 |
|
|
69 |
public Double getFunctionA() { |
/** Only used for {@link Copyable<AttributeMetaData>#copy()} **/ |
70 |
return functionA; |
private AttributeMetadataImpl() { |
71 |
} |
} |
72 |
|
|
73 |
public void setFunctionA(Double functionA) { |
public AttributeMetadataImpl(final AttributeDescriptor attDesc, |
74 |
this.functionA = functionA; |
final int weight, final List<String> langs) { |
75 |
|
this( new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs); |
76 |
|
setWeight(weight); |
77 |
} |
} |
78 |
|
|
79 |
public void setVisible(boolean visible) { |
public AttributeMetadataImpl(final AttributeDescriptor attDesc, |
80 |
this.visible = visible; |
final List<String> langs) { |
81 |
|
this(new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs); |
82 |
} |
} |
83 |
|
|
84 |
/** |
/** |
85 |
* When listed, the attributes are listed according to their weight (heavier |
* Creates an {@link AttributeMetadataImpl} object with the following |
|
* => 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. |
|
|
**/ |
|
|
protected List<Object> nodataValues = new ArrayList<Object>(); |
|
|
|
|
|
/** |
|
|
* For numerical attributes the value can be transformed by VALUE*X+A when |
|
|
* presented on screen |
|
|
**/ |
|
|
protected Double functionX = 1.; |
|
|
|
|
|
/** |
|
|
* For numerical attributes the value can be transformed by VALUE*X+A when |
|
|
* presented on screen |
|
|
**/ |
|
|
protected Double functionA = 0.; |
|
|
|
|
|
/** |
|
|
* Creates an {@link AttributeMetadata} object with the following |
|
86 |
* information |
* information |
87 |
* |
* |
88 |
* @param colIdx |
* @param colIdx |
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); |
104 |
this.title = title; |
this.title = title; |
105 |
this.desc = desc; |
this.desc = desc; |
106 |
|
this.visible = visible; |
107 |
|
this.unit = unit; |
108 |
|
} |
109 |
|
|
110 |
// The THE_GEOM and shall never be visible! |
/** |
111 |
if (name.getLocalPart().equalsIgnoreCase("the_geom")) |
* Creates an {@link AttributeMetadataImpl} object with the following |
112 |
this.visible = false; |
* information |
113 |
else |
* |
114 |
this.visible = visible; |
* @param colIdx |
115 |
|
* The column index of this attribute in the underlying |
116 |
|
* table/dbf/etc... |
117 |
|
* @param visible |
118 |
|
* Shall this attribute be displayed or hidden from the user? |
119 |
|
* @param unit |
120 |
|
* {@link String} of the unit that the information is in |
121 |
|
*/ |
122 |
|
public AttributeMetadataImpl(final Name name, final Boolean visible, |
123 |
|
final String unit) { |
124 |
|
this.setName(name); |
125 |
|
this.visible = visible; |
126 |
this.unit = unit; |
this.unit = unit; |
127 |
} |
} |
128 |
|
|
129 |
/** |
/** |
130 |
* Creates an {@link AttributeMetadata} object with the following |
* Creates a new visible {@link AttributeMetadataImpl} |
131 |
|
*/ |
132 |
|
public AttributeMetadataImpl(final Name name, final List<String> langs) { |
133 |
|
this(name, true, new Translation(langs, name.getLocalPart()), |
134 |
|
new Translation(), ""); |
135 |
|
} |
136 |
|
|
137 |
|
/** |
138 |
|
* Creates a new visible {@link AttributeMetadataImpl} |
139 |
|
*/ |
140 |
|
public AttributeMetadataImpl(final Name name, final String defaultTitle, |
141 |
|
final List<String> langs) { |
142 |
|
this(name, true, new Translation(langs, defaultTitle), |
143 |
|
new Translation(), ""); |
144 |
|
} |
145 |
|
|
146 |
|
/** |
147 |
|
* Creates an {@link AttributeMetadataImpl} object with the following |
148 |
* information |
* information |
149 |
* |
* |
150 |
* @param visible |
* @param visible |
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 String defaultTitle) { |
public AttributeMetadataImpl(final String localName, |
169 |
this(localName, true, new Translation(defaultTitle), new Translation(), |
final List<String> langs) { |
170 |
""); |
this(localName, true, new Translation(langs, localName), |
171 |
|
new Translation(), ""); |
172 |
} |
} |
173 |
|
|
174 |
/** |
/** |
175 |
* Creates a new visible {@link AttributeMetadata} with default (no) values. |
* Creates a new visible {@link AttributeMetadataImpl} |
176 |
*/ |
*/ |
177 |
public AttributeMetadata(final Name name, final String defaultTitle) { |
public AttributeMetadataImpl(final String localName, |
178 |
this(name, true, new Translation(defaultTitle), new Translation(), ""); |
final String defaultTitle, final List<String> langs) { |
179 |
|
this(localName, true, new Translation(langs, defaultTitle), |
180 |
|
new Translation(), ""); |
181 |
} |
} |
182 |
|
|
183 |
/** |
/** |
184 |
* Creates a new visible {@link AttributeMetadata} with default (no) values. |
* Orders the attributes according to their {@link #weight}. Heavier => |
185 |
|
* further down. |
186 |
*/ |
*/ |
187 |
public AttributeMetadata(final Name name) { |
@Override |
188 |
this(name, true, new Translation(name.getLocalPart()), |
public int compareTo(final AttributeMetadataInterface atm2) { |
189 |
new Translation(), ""); |
return new Integer(weight).compareTo(new Double(atm2.getWeight()) |
190 |
|
.intValue()); |
191 |
} |
} |
192 |
|
|
193 |
/** |
/** |
194 |
* Creates a new visible {@link AttributeMetadata} with default (no) values. |
* @see Copyable inferface |
195 |
*/ |
*/ |
196 |
public AttributeMetadata(final String localName) { |
@Override |
197 |
this(localName, true, new Translation(localName), new Translation(), ""); |
public AttributeMetadataInterface copy() { |
198 |
} |
return copyTo(new AttributeMetadataImpl()); |
|
|
|
|
/** Only used for {@link Copyable<AttributeMetaData>#copy()} **/ |
|
|
private AttributeMetadata() { |
|
|
} |
|
|
|
|
|
public AttributeMetadata(AttributeDescriptor attDesc) { |
|
|
this(attDesc.getName()); |
|
|
} |
|
|
|
|
|
public AttributeMetadata(AttributeDescriptor attDesc, int weight) { |
|
|
this(attDesc.getName()); |
|
|
setWeight(weight); |
|
|
} |
|
|
|
|
|
public boolean isVisible() { |
|
|
return visible; |
|
|
} |
|
|
|
|
|
public void setVisible(final Boolean visible) { |
|
|
|
|
|
// 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; |
|
|
} |
|
|
|
|
|
public Translation getTitle() { |
|
|
return title; |
|
|
} |
|
|
|
|
|
public void setTitle(final Translation title) { |
|
|
this.title = title; |
|
|
} |
|
|
|
|
|
public Translation getDesc() { |
|
|
return desc; |
|
|
} |
|
|
|
|
|
public void setDesc(final Translation desc) { |
|
|
this.desc = desc; |
|
|
} |
|
|
|
|
|
public String getUnit() { |
|
|
return unit; |
|
|
} |
|
|
|
|
|
public void setUnit(final String unit) { |
|
|
this.unit = unit; |
|
199 |
} |
} |
200 |
|
|
201 |
|
/** |
202 |
|
* @see Copyable inferface |
203 |
|
*/ |
204 |
@Override |
@Override |
205 |
public AttributeMetadata copyTo(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()); |
211 |
.getLocalPart())); |
.getLocalPart())); |
212 |
|
|
213 |
amd.setWeight(getWeight()); |
amd.setWeight(getWeight()); |
|
amd.setFunctionX(getFunctionX()); |
|
|
amd.setFunctionA(getFunctionA()); |
|
214 |
|
|
215 |
for (Object nodataValue : getNodataValues()) { |
if (amd instanceof AttributeMetadataImpl) { |
216 |
amd.getNodataValues().add(nodataValue); |
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 |
@Override |
// only to be used by copyTo() |
227 |
public AttributeMetadata copy() { |
private void setNodataValues(HashSet<Object> nodataValues_) { |
228 |
return copyTo(new AttributeMetadata()); |
nodataValues = nodataValues_; |
229 |
} |
} |
230 |
|
|
231 |
/** |
public Double getFunctionA() { |
232 |
* The local Name. E.g. the name of the DBF column as a String |
return functionA; |
|
*/ |
|
|
public String getLocalName() { |
|
|
return getName().getLocalPart(); |
|
233 |
} |
} |
234 |
|
|
235 |
/** |
public Double getFunctionX() { |
236 |
* The fully qualified Name of the attribute, e.g. org.bla.plo:blub |
return functionX; |
|
*/ |
|
|
public Name getName() { |
|
|
return name; |
|
237 |
} |
} |
238 |
|
|
239 |
/** |
/** |
240 |
* The fully qualified Name of the attribute, e.g. org.bla.plo:blub |
* @return a number between 0 (bad) and 1 (good) that is calculated from the |
241 |
|
* amount of translation available. If this attribute is not |
242 |
|
* {@link #visible}, it will return 1. |
243 |
*/ |
*/ |
244 |
public void setName(org.opengis.feature.type.Name name) { |
@Override |
245 |
this.name = name; |
public double getQuality(final List<String> languages) { |
|
} |
|
246 |
|
|
247 |
/** |
if (!isVisible()) |
248 |
* The fully qualified Name of the attribute, e.g. org.bla.plo:blub |
return 1.; |
249 |
*/ |
|
250 |
public void setLocalName(String localName) { |
return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil |
251 |
this.name = new NameImpl(localName); |
.qmTranslation(languages, getDesc()) * 1.) / 3.; |
252 |
} |
} |
253 |
|
|
254 |
/** |
public void setFunctionA(final Double functionA) { |
255 |
* Orders the Attributes according to their weight. Heavier => further down. |
this.functionA = functionA; |
|
*/ |
|
|
@Override |
|
|
public int compareTo(AttributeMetadata atm2) { |
|
|
// Double double1 = new Double(1./weight); |
|
|
// double double2 = 1./atm2.getWeight(); |
|
|
return new Integer(weight).compareTo(atm2.getWeight()); |
|
256 |
} |
} |
257 |
|
|
258 |
/** |
public void setFunctionX(final Double functionX) { |
259 |
* @return a number between 0 (bad) and 1 (good) that is calculated from the amount of translation available in the visible attributes |
this.functionX = functionX; |
|
*/ |
|
|
public double getQuality(List<String> languages) { |
|
|
return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil |
|
|
.qmTranslation(languages, getDesc()) * 1.) / 3.; |
|
260 |
} |
} |
261 |
|
|
262 |
|
|
263 |
} |
} |