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;
}
otherDetails.put(key, value);
+ FeatureAttributes.getInstance().addAttribute(this.type, key);
}
}
--- /dev/null
+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<String, Set<String>> 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<String> 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>(
+ String.CASE_INSENSITIVE_ORDER));
+ }
+
+ attributes.get(featureType).add(attName);
+ }
+}