X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2Ffeatures%2FSequenceFeatures.java;h=5fa9a3cf120e0d047daf6749da729bac421d2df7;hb=b5a5b5fa7fe3fb77e55acf930d25d10ddc0e80e2;hp=c6af3ea2f18acc6cf0627bb19bb6980a42c5fc40;hpb=f14246a28441f24b39b0516282513fbf6196e46c;p=jalview.git diff --git a/src/jalview/datamodel/features/SequenceFeatures.java b/src/jalview/datamodel/features/SequenceFeatures.java index c6af3ea..5fa9a3c 100644 --- a/src/jalview/datamodel/features/SequenceFeatures.java +++ b/src/jalview/datamodel/features/SequenceFeatures.java @@ -4,12 +4,13 @@ import jalview.datamodel.SequenceFeature; 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 @@ -33,7 +34,12 @@ public class SequenceFeatures implements SequenceFeaturesI */ public SequenceFeatures() { - featureStore = new HashMap(); + /* + * 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()); } /** @@ -43,6 +49,11 @@ public class SequenceFeatures implements SequenceFeaturesI 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) { @@ -155,8 +166,21 @@ public class SequenceFeatures implements SequenceFeaturesI */ protected Iterable 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 types = new ArrayList(Arrays.asList(type)); + types.remove(null); + return types; } /**