*/
public class FeatureAttributes
{
+ public enum Datatype
+ {
+ Character, Number, Mixed
+ }
+
private static FeatureAttributes instance = new FeatureAttributes();
/*
*/
boolean hasValue = false;
+ Datatype type;
+
/**
* Note one instance of this attribute, recording unique, non-null names,
* and the min/max of any numerical values
try
{
float f = Float.valueOf(value);
- min = Float.min(min, f);
- max = Float.max(max, f);
+ min = hasValue ? Float.min(min, f) : f;
+ max = hasValue ? Float.max(max, f) : f;
hasValue = true;
+ type = (type == null || type == Datatype.Number) ? Datatype.Number
+ : Datatype.Mixed;
} catch (NumberFormatException e)
{
- // ok, wasn't a number, ignore for min-max purposes
+ // not a number, ignore for min-max purposes
+ type = (type == null || type == Datatype.Character)
+ ? Datatype.Character
+ : Datatype.Mixed;
}
}
}
return null;
}
+ public Datatype getType()
+ {
+ return type;
+ }
+
/**
* Adds the given description to the list of known descriptions (without
* duplication)
}
attData.addDescription(description);
}
+
+ /**
+ * Answers the datatype of the feature, which is one of Character, Number or
+ * Mixed (or null if not known), as discovered from values recorded.
+ *
+ * @param featureType
+ * @param attName
+ * @return
+ */
+ public Datatype getDatatype(String featureType, String... attName)
+ {
+ Map<String[], AttributeData> atts = attributes.get(featureType);
+ if (atts != null)
+ {
+ AttributeData attData = atts.get(attName);
+ if (attData != null)
+ {
+ return attData.getType();
+ }
+ }
+ return null;
+ }
}