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; |
36 |
import org.geotools.feature.NameImpl; |
import org.geotools.feature.NameImpl; |
37 |
import org.opengis.feature.type.AttributeDescriptor; |
import org.opengis.feature.type.AttributeDescriptor; |
|
import org.opengis.feature.type.Name; |
|
38 |
|
|
39 |
import skrueger.geotools.Copyable; |
import skrueger.geotools.Copyable; |
40 |
import skrueger.geotools.StyledLayerInterface; |
import skrueger.geotools.StyledLayerInterface; |
47 |
* |
* |
48 |
* @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
* @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
49 |
*/ |
*/ |
50 |
public class AttributeMetadata implements Copyable<AttributeMetadata>, |
public class AttributeMetadataImpl extends AbstractAttributeMetadata implements |
51 |
Comparable<AttributeMetadata> { |
QualityQuantizable { |
|
|
|
|
static private final Logger LOGGER = Logger |
|
|
.getLogger(AttributeMetadata.class); |
|
52 |
|
|
53 |
/** Translation of the attribute's description **/ |
static private final Logger LOGGER = Logger |
54 |
protected Translation desc = new Translation(); |
.getLogger(AttributeMetadataImpl.class); |
55 |
|
|
56 |
/** |
/** |
57 |
* 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 |
65 |
**/ |
**/ |
66 |
protected Double functionX = 1.; |
protected Double functionX = 1.; |
67 |
|
|
|
/** 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. TODO not implemented yet |
|
|
**/ |
|
|
protected List<Object> nodataValues = new ArrayList<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; |
|
|
|
|
68 |
/** Only used for {@link Copyable<AttributeMetaData>#copy()} **/ |
/** Only used for {@link Copyable<AttributeMetaData>#copy()} **/ |
69 |
private AttributeMetadata() { |
private AttributeMetadataImpl() { |
70 |
} |
} |
71 |
|
|
72 |
public AttributeMetadata(final AttributeDescriptor attDesc, final int weight, |
public AttributeMetadataImpl(final AttributeDescriptor attDesc, |
73 |
final List<String> langs) { |
final int weight, final List<String> langs) { |
74 |
this(attDesc.getName(), langs); |
this( new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs); |
75 |
setWeight(weight); |
setWeight(weight); |
76 |
} |
} |
77 |
|
|
78 |
public AttributeMetadata(final AttributeDescriptor attDesc, final List<String> langs) { |
public AttributeMetadataImpl(final AttributeDescriptor attDesc, |
79 |
this(attDesc.getName(), langs); |
final List<String> langs) { |
80 |
|
this(new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs); |
81 |
} |
} |
82 |
|
|
83 |
/** |
/** |
84 |
* Creates an {@link AttributeMetadata} object with the following |
* Creates an {@link AttributeMetadataImpl} object with the following |
85 |
* information |
* information |
86 |
* |
* |
87 |
* @param colIdx |
* @param colIdx |
96 |
* @param unit |
* @param unit |
97 |
* {@link String} of the unit that the information is in |
* {@link String} of the unit that the information is in |
98 |
*/ |
*/ |
99 |
public AttributeMetadata(final Name name, final Boolean visible, |
public AttributeMetadataImpl(final NameImpl name, final Boolean visible, |
100 |
final Translation title, final Translation desc, final String unit) { |
final Translation title, final Translation desc, final String unit) { |
101 |
|
|
102 |
this.setName(name); |
this.setName(name); |
107 |
} |
} |
108 |
|
|
109 |
/** |
/** |
110 |
* Creates a new visible {@link AttributeMetadata} |
* Creates an {@link AttributeMetadataImpl} object with the following |
111 |
|
* information |
112 |
|
* |
113 |
|
* @param colIdx |
114 |
|
* The column index of this attribute in the underlying |
115 |
|
* table/dbf/etc... |
116 |
|
* @param visible |
117 |
|
* Shall this attribute be displayed or hidden from the user? |
118 |
|
* @param unit |
119 |
|
* {@link String} of the unit that the information is in |
120 |
*/ |
*/ |
121 |
public AttributeMetadata(final Name name, final List<String> langs) { |
public AttributeMetadataImpl(final NameImpl name, final Boolean visible, |
122 |
|
final String unit) { |
123 |
|
this.setName(name); |
124 |
|
this.visible = visible; |
125 |
|
this.unit = unit; |
126 |
|
} |
127 |
|
|
128 |
|
/** |
129 |
|
* Creates a new visible {@link AttributeMetadataImpl} |
130 |
|
*/ |
131 |
|
public AttributeMetadataImpl(final NameImpl name, final List<String> langs) { |
132 |
this(name, true, new Translation(langs, name.getLocalPart()), |
this(name, true, new Translation(langs, name.getLocalPart()), |
133 |
new Translation(), ""); |
new Translation(), ""); |
134 |
} |
} |
135 |
|
|
136 |
/** |
/** |
137 |
* Creates a new visible {@link AttributeMetadata} |
* Creates a new visible {@link AttributeMetadataImpl} |
138 |
*/ |
*/ |
139 |
public AttributeMetadata(final Name name, final String defaultTitle, |
public AttributeMetadataImpl(final NameImpl name, final String defaultTitle, |
140 |
final List<String> langs) { |
final List<String> langs) { |
141 |
this(name, true, new Translation(langs, defaultTitle), |
this(name, true, new Translation(langs, defaultTitle), |
142 |
new Translation(), ""); |
new Translation(), ""); |
143 |
} |
} |
144 |
|
|
145 |
/** |
/** |
146 |
* Creates an {@link AttributeMetadata} object with the following |
* Creates an {@link AttributeMetadataImpl} object with the following |
147 |
* information |
* information |
148 |
* |
* |
149 |
* @param visible |
* @param visible |
155 |
* @param unit |
* @param unit |
156 |
* {@link String} of the unit that the information is in |
* {@link String} of the unit that the information is in |
157 |
*/ |
*/ |
158 |
public AttributeMetadata(final String localName, final Boolean visible, |
public AttributeMetadataImpl(final String localName, final Boolean visible, |
159 |
final Translation title, final Translation desc, final String unit) { |
final Translation title, final Translation desc, final String unit) { |
160 |
this(new NameImpl(localName), true, title, desc, ""); |
this(new NameImpl(localName), true, title, desc, ""); |
161 |
} |
} |
162 |
|
|
163 |
/** |
/** |
164 |
* Creates a new visible {@link AttributeMetadata} with default (no) values. |
* Creates a new visible {@link AttributeMetadataImpl} with default (no) |
165 |
|
* values. |
166 |
*/ |
*/ |
167 |
public AttributeMetadata(final String localName, final List<String> langs) { |
public AttributeMetadataImpl(final String localName, |
168 |
|
final List<String> langs) { |
169 |
this(localName, true, new Translation(langs, localName), |
this(localName, true, new Translation(langs, localName), |
170 |
new Translation(), ""); |
new Translation(), ""); |
171 |
} |
} |
172 |
|
|
173 |
/** |
/** |
174 |
* Creates a new visible {@link AttributeMetadata} |
* Creates a new visible {@link AttributeMetadataImpl} |
175 |
*/ |
*/ |
176 |
public AttributeMetadata(final String localName, final String defaultTitle, |
public AttributeMetadataImpl(final String localName, |
177 |
final List<String> langs) { |
final String defaultTitle, final List<String> langs) { |
178 |
this(localName, true, new Translation(langs, defaultTitle), |
this(localName, true, new Translation(langs, defaultTitle), |
179 |
new Translation(), ""); |
new Translation(), ""); |
180 |
} |
} |
185 |
*/ |
*/ |
186 |
@Override |
@Override |
187 |
public int compareTo(final AttributeMetadata atm2) { |
public int compareTo(final AttributeMetadata atm2) { |
188 |
return new Integer(weight).compareTo(atm2.getWeight()); |
return new Integer(weight).compareTo(new Double(atm2.getWeight()) |
189 |
|
.intValue()); |
190 |
} |
} |
191 |
|
|
192 |
/** |
/** |
194 |
*/ |
*/ |
195 |
@Override |
@Override |
196 |
public AttributeMetadata copy() { |
public AttributeMetadata copy() { |
197 |
return copyTo(new AttributeMetadata()); |
return copyTo(new AttributeMetadataImpl()); |
198 |
} |
} |
199 |
|
|
200 |
/** |
/** |
210 |
.getLocalPart())); |
.getLocalPart())); |
211 |
|
|
212 |
amd.setWeight(getWeight()); |
amd.setWeight(getWeight()); |
|
amd.setFunctionX(getFunctionX()); |
|
|
amd.setFunctionA(getFunctionA()); |
|
213 |
|
|
214 |
for (final Object nodataValue : getNodataValues()) { |
if (amd instanceof AttributeMetadataImpl) { |
215 |
amd.getNodataValues().add(nodataValue); |
AttributeMetadataImpl amd_ = (AttributeMetadataImpl) amd; |
216 |
|
|
217 |
|
amd_.setFunctionX(getFunctionX()); |
218 |
|
amd_.setFunctionA(getFunctionA()); |
219 |
|
amd_.setNodataValues(getNodataValues()); |
220 |
} |
} |
221 |
|
|
222 |
return amd; |
return amd; |
223 |
} |
} |
224 |
|
|
225 |
public Translation getDesc() { |
// only to be used by copyTo() |
226 |
return desc; |
private void setNodataValues(HashSet<Object> nodataValues_) { |
227 |
|
nodataValues = nodataValues_; |
228 |
} |
} |
229 |
|
|
230 |
public Double getFunctionA() { |
public Double getFunctionA() { |
236 |
} |
} |
237 |
|
|
238 |
/** |
/** |
|
* 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 List<Object> getNodataValues() { |
|
|
return nodataValues; |
|
|
} |
|
|
|
|
|
/** |
|
239 |
* @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 |
240 |
* amount of translation available. If this attribute is not |
* amount of translation available. If this attribute is not |
241 |
* {@link #visible}, it will return 1. |
* {@link #visible}, it will return 1. |
242 |
*/ |
*/ |
243 |
|
@Override |
244 |
public double getQuality(final List<String> languages) { |
public double getQuality(final List<String> languages) { |
245 |
|
|
246 |
if (!isVisible()) |
if (!isVisible()) |
250 |
.qmTranslation(languages, getDesc()) * 1.) / 3.; |
.qmTranslation(languages, getDesc()) * 1.) / 3.; |
251 |
} |
} |
252 |
|
|
|
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; |
|
|
} |
|
|
|
|
253 |
public void setFunctionA(final Double functionA) { |
public void setFunctionA(final Double functionA) { |
254 |
this.functionA = functionA; |
this.functionA = functionA; |
255 |
} |
} |
258 |
this.functionX = functionX; |
this.functionX = functionX; |
259 |
} |
} |
260 |
|
|
|
/** |
|
|
* 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. <code>org.bla.plo:blub</code> |
|
|
*/ |
|
|
public void setName(final Name name) { |
|
|
this.name = name; |
|
|
} |
|
|
|
|
|
public void setNodataValues(final List<Object> 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; |
|
|
} |
|
|
|
|
|
/** |
|
|
* 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; |
|
|
} |
|
261 |
|
|
|
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(); |
|
|
} |
|
262 |
} |
} |