From d3e33a7b85e3369da8ff51ff9af7cf6132865e2a Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 30 Oct 2017 16:54:55 +0000 Subject: [PATCH] JAL-2808 remember attribute keys by feature type --- src/jalview/datamodel/SequenceFeature.java | 2 + .../datamodel/features/FeatureAttributes.java | 71 ++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/jalview/datamodel/features/FeatureAttributes.java diff --git a/src/jalview/datamodel/SequenceFeature.java b/src/jalview/datamodel/SequenceFeature.java index 8f82a1a..5029da5 100755 --- a/src/jalview/datamodel/SequenceFeature.java +++ b/src/jalview/datamodel/SequenceFeature.java @@ -21,6 +21,7 @@ package jalview.datamodel; import jalview.datamodel.features.FeatureAttributeType; +import jalview.datamodel.features.FeatureAttributes; import jalview.datamodel.features.FeatureLocationI; import jalview.datamodel.features.FeatureSourceI; import jalview.datamodel.features.FeatureSources; @@ -424,6 +425,7 @@ public class SequenceFeature implements FeatureLocationI } otherDetails.put(key, value); + FeatureAttributes.getInstance().addAttribute(this.type, key); } } diff --git a/src/jalview/datamodel/features/FeatureAttributes.java b/src/jalview/datamodel/features/FeatureAttributes.java new file mode 100644 index 0000000..7990f6b --- /dev/null +++ b/src/jalview/datamodel/features/FeatureAttributes.java @@ -0,0 +1,71 @@ +package jalview.datamodel.features; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +/** + * A singleton class to hold the set of attributes known for each feature type + */ +public class FeatureAttributes +{ + private static FeatureAttributes instance = new FeatureAttributes(); + + private Map> attributes; + + /** + * Answers the singleton instance of this class + * + * @return + */ + public static FeatureAttributes getInstance() + { + return instance; + } + + private FeatureAttributes() + { + attributes = new HashMap<>(); + } + + /** + * Answers the attributes known for the given feature type, in alphabetical + * order (not case sensitive), or an empty set if no attributes are known + * + * @param featureType + * @return + */ + public Iterable getAttributes(String featureType) + { + if (!attributes.containsKey(featureType)) + { + return Collections.emptySet(); + } + + return attributes.get(featureType); + } + + /** + * Records the given attribute name for the given feature type + * + * @param featureType + * @param attName + */ + public void addAttribute(String featureType, String attName) + { + if (featureType == null || attName == null) + { + return; + } + + if (!attributes.containsKey(featureType)) + { + attributes.put(featureType, new TreeSet( + String.CASE_INSENSITIVE_ORDER)); + } + + attributes.get(featureType).add(attName); + } +} -- 1.7.10.2