X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2Ffeatures%2FFeatureAttributes.java;h=3dc4f191950acf6428282e5b5d6437f4b90a424b;hb=9feb54a4d32293b760afcdc29672fb6a880c6cbb;hp=ed6575014c6d57bb7df43dffa7b4f6ab05f89a51;hpb=9bde0814fff97f50e3ac6165a9fb83787c37d39a;p=jalview.git diff --git a/src/jalview/datamodel/features/FeatureAttributes.java b/src/jalview/datamodel/features/FeatureAttributes.java index ed65750..3dc4f19 100644 --- a/src/jalview/datamodel/features/FeatureAttributes.java +++ b/src/jalview/datamodel/features/FeatureAttributes.java @@ -34,6 +34,11 @@ public class FeatureAttributes */ 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 @@ -43,27 +48,19 @@ public class FeatureAttributes */ 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 } } } @@ -80,6 +77,27 @@ public class FeatureAttributes } 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); + } + } + } } /** @@ -188,4 +206,59 @@ public class FeatureAttributes } 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 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 atts = attributes.get(featureType); + if (atts == null) + { + atts = new TreeMap( + 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); + } }