package jalview.datamodel.features; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; 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 List getAttributes(String featureType) { if (!attributes.containsKey(featureType)) { return Collections. emptyList(); } return new ArrayList<>(attributes.get(featureType)); } /** * Answers true if at least one attribute is known for the given feature type, * else false * * @param featureType * @return */ public boolean hasAttributes(String featureType) { if (attributes.containsKey(featureType)) { if (!attributes.get(featureType).isEmpty()) { return true; } } return false; } /** * 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); } }