From 788e840cc150aa4777a370cebfdf5d17589bbbaf Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 31 May 2018 14:20:50 +0100 Subject: [PATCH] JAL-2808 don't capture or report min-max for mixed text/numeric attribute --- .../datamodel/features/FeatureAttributes.java | 50 +++++++++++++------- src/jalview/gui/FeatureTypeSettings.java | 2 +- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/jalview/datamodel/features/FeatureAttributes.java b/src/jalview/datamodel/features/FeatureAttributes.java index e359b62..10249f3 100644 --- a/src/jalview/datamodel/features/FeatureAttributes.java +++ b/src/jalview/datamodel/features/FeatureAttributes.java @@ -87,8 +87,8 @@ public class FeatureAttributes Datatype type; /** - * Note one instance of this attribute, recording unique, non-null names, - * and the min/max of any numerical values + * Note one instance of this attribute, recording unique, non-null + * descriptions, and the min/max of any numerical values * * @param desc * @param value @@ -99,20 +99,35 @@ public class FeatureAttributes if (value != null) { - try - { - float f = Float.valueOf(value); - 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) + value = value.trim(); + + /* + * Parse numeric value unless we have previously + * seen text data for this attribute type + */ + if (type == null || type == Datatype.Number) { - // not a number, ignore for min-max purposes - type = (type == null || type == Datatype.Character) - ? Datatype.Character - : Datatype.Mixed; + try + { + float f = Float.valueOf(value); + 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) + { + /* + * non-numeric data: treat attribute as Character (or Mixed) + */ + type = (type == null || type == Datatype.Character) + ? Datatype.Character + : Datatype.Mixed; + min = 0f; + max = 0f; + hasValue = false; + } } } } @@ -284,9 +299,8 @@ public class FeatureAttributes /** * 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. + * feature type, if known, else null. Attributes with a mixture of text and + * numeric values are considered text (do not return a min-max range). * * @param featureType * @param attName diff --git a/src/jalview/gui/FeatureTypeSettings.java b/src/jalview/gui/FeatureTypeSettings.java index 89c693f..e13f6ee 100644 --- a/src/jalview/gui/FeatureTypeSettings.java +++ b/src/jalview/gui/FeatureTypeSettings.java @@ -1551,7 +1551,7 @@ public class FeatureTypeSettings extends JalviewDialog condCombo.removeAllItems(); for (Condition c : Condition.values()) { - if ((c.isNumeric() && type != Datatype.Character) + if ((c.isNumeric() && type == Datatype.Number) || (!c.isNumeric() && type != Datatype.Number)) { condCombo.addItem(c); -- 1.7.10.2