import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashMap;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import java.util.TreeMap;
/**
* A class that stores sequence features in a way that supports efficient
*/
public SequenceFeatures()
{
- featureStore = new HashMap<String, FeatureStore>();
+ /*
+ * use a TreeMap so that features are returned in alphabetical order of type
+ * wrap as a synchronized map for add and delete operations
+ */
+ featureStore = Collections
+ .synchronizedSortedMap(new TreeMap<String, FeatureStore>());
}
/**
public boolean add(SequenceFeature sf)
{
String type = sf.getType();
+ if (type == null)
+ {
+ System.err.println("Feature type may not be null: " + sf.toString());
+ return false;
+ }
if (featureStore.get(type) == null)
{
*/
protected Iterable<String> varargToTypes(String... type)
{
- return type == null || type.length == 0 ? featureStore
- .keySet() : Arrays.asList(type);
+ if (type == null || type.length == 0)
+ {
+ /*
+ * no vararg parameter supplied
+ */
+ return featureStore.keySet();
+ }
+
+ /*
+ * else make a copy of the list, and remove any null value just in case,
+ * as it would cause errors looking up the features Map
+ */
+ List<String> types = new ArrayList<String>(Arrays.asList(type));
+ types.remove(null);
+ return types;
}
/**