*/
float max = 0f;
+ /*
+ * flag is set true if any numeric value is detected for this attribute
+ */
+ boolean hasValue = false;
+
/**
* Note one instance of this attribute, recording unique, non-null names,
* and the min/max of any numerical values
*/
void addInstance(String desc, String value)
{
- if (desc != null)
+ addDescription(desc);
+
+ if (value != null)
{
- if (description == null)
- {
- description = new ArrayList<>();
- }
- if (!description.contains(desc))
+ try
{
- description.add(desc);
- }
- if (value != null)
+ float f = Float.valueOf(value);
+ min = Float.min(min, f);
+ max = Float.max(max, f);
+ hasValue = true;
+ } catch (NumberFormatException e)
{
- try
- {
- float f = Float.valueOf(value);
- min = Float.min(min, f);
- max = Float.max(max, f);
- } catch (NumberFormatException e)
- {
- // ok, wasn't a number
- }
+ // ok, wasn't a number, ignore for min-max purposes
}
}
}
}
return null;
}
+
+ /**
+ * Adds the given description to the list of known descriptions (without
+ * duplication)
+ *
+ * @param desc
+ */
+ public void addDescription(String desc)
+ {
+ if (desc != null)
+ {
+ if (description == null)
+ {
+ description = new ArrayList<>();
+ }
+ if (!description.contains(desc))
+ {
+ description.add(desc);
+ }
+ }
+ }
}
/**
}
return desc;
}
+
+ /**
+ * Answers the [min, max] value range of the given attribute for the given
+ * feature type, if known, else null. Attributes which only have text values
+ * would normally return null, however text values which happen to be numeric
+ * could result in a 'min-max' range.
+ *
+ * @param featureType
+ * @param attName
+ * @return
+ */
+ public float[] getMinMax(String featureType, String attName)
+ {
+ Map<String, AttributeData> atts = attributes.get(featureType);
+ if (atts != null)
+ {
+ AttributeData attData = atts.get(attName);
+ if (attData != null && attData.hasValue)
+ {
+ return new float[] { attData.min, attData.max };
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Records the given attribute description for the given feature type
+ *
+ * @param featureType
+ * @param attName
+ * @param description
+ */
+ public void addDescription(String featureType, String attName,
+ String description)
+ {
+ if (featureType == null || attName == null)
+ {
+ return;
+ }
+
+ Map<String, AttributeData> atts = attributes.get(featureType);
+ if (atts == null)
+ {
+ atts = new TreeMap<String, AttributeData>(
+ String.CASE_INSENSITIVE_ORDER);
+ attributes.put(featureType, atts);
+ }
+ AttributeData attData = atts.get(attName);
+ if (attData == null)
+ {
+ attData = new AttributeData();
+ atts.put(attName, attData);
+ }
+ attData.addDescription(description);
+ }
}