X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2Ffeatures%2FSequenceFeatures.java;h=6165d0abb7e0340b8560c0a0636b5f25c9b475fd;hb=5c10f71b18bb8a9e3320440cc1eaa95350d56120;hp=45d6ede1f063dbf8a5d8a2cf45708bd04d9b61eb;hpb=64c1e734115c6554ef56a3e0feb7cdea40cd7f41;p=jalview.git diff --git a/src/jalview/datamodel/features/SequenceFeatures.java b/src/jalview/datamodel/features/SequenceFeatures.java index 45d6ede..6165d0a 100644 --- a/src/jalview/datamodel/features/SequenceFeatures.java +++ b/src/jalview/datamodel/features/SequenceFeatures.java @@ -3,7 +3,7 @@ package jalview.datamodel.features; import jalview.datamodel.SequenceFeature; import java.util.ArrayList; -import java.util.Collections; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -56,64 +56,40 @@ public class SequenceFeatures } /** - * Returns a (possibly empty) list of features of the given type which overlap - * the (inclusive) sequence position range + * Returns a (possibly empty) list of features, optionally restricted to + * specified types, which overlap the given (inclusive) sequence position + * range * - * @param type * @param from * @param to + * @param type * @return */ - public List findFeatures(String type, int from, - int to) - { - FeatureStore features = featureStore.get(type); - if (features == null) - { - return Collections.emptyList(); - } - return features.findOverlappingFeatures(from, to); - } - - /** - * Answers a list of all positional features stored, in no particular - * guaranteed order - * - * @return - */ - public List getPositionalFeatures() + public List findFeatures(int from, int to, + String... type) { List result = new ArrayList(); - for (FeatureStore featureSet : featureStore.values()) + + for (String featureType : varargToTypes(type)) { - result.addAll(featureSet.getPositionalFeatures()); + FeatureStore features = featureStore.get(featureType); + if (features != null) + { + result.addAll(features.findOverlappingFeatures(from, to)); + } } - return result; - } - - /** - * Answers a list of all features stored, in no particular guaranteed order - * - * @return - */ - public List getAllFeatures() - { - List result = new ArrayList(); - - result.addAll(getPositionalFeatures()); - - result.addAll(getNonPositionalFeatures()); return result; } /** - * Answers a list of all features stored of the specified type, in no - * particular guaranteed order + * Answers a list of all features stored, optionally restricted to specified + * types, in no particular guaranteed order * + * @param type * @return */ - public List getAllFeatures(String type) + public List getAllFeatures(String... type) { List result = new ArrayList(); @@ -125,84 +101,81 @@ public class SequenceFeatures } /** - * Answers a list of all non-positional features stored, in no particular - * guaranteed order + * Answers a list of all positional features, optionally restricted to + * specified types, in no particular guaranteed order * + * @param type * @return */ - public List getNonPositionalFeatures() + public List getPositionalFeatures(String... type) { List result = new ArrayList(); - for (FeatureStore featureSet : featureStore.values()) - { - result.addAll(featureSet.getNonPositionalFeatures()); - } - return result; - } - /** - * Answers a list of all contact features stored, in no particular guaranteed - * order - * - * @return - */ - public List getContactFeatures() - { - List result = new ArrayList(); - for (FeatureStore featureSet : featureStore.values()) + for (String featureType : varargToTypes(type)) { - result.addAll(featureSet.getContactFeatures()); + FeatureStore featureSet = featureStore.get(featureType); + if (featureSet != null) + { + result.addAll(featureSet.getPositionalFeatures()); + } } return result; } /** - * Answers a list of all positional features of the given type, in no - * particular guaranteed order + * A convenience method that converts a vararg for feature types to an + * Iterable, replacing the value with the stored feature types if it is null + * or empty * + * @param type * @return */ - public List getPositionalFeatures(String type) + protected Iterable varargToTypes(String... type) { - List result = new ArrayList(); - FeatureStore featureSet = featureStore.get(type); - if (featureSet != null) - { - result.addAll(featureSet.getPositionalFeatures()); - } - return result; + return type == null || type.length == 0 ? featureStore + .keySet() : Arrays.asList(type); } /** - * Answers a list of all contact features of the given type, in no particular - * guaranteed order + * Answers a list of all contact features, optionally restricted to specified + * types, in no particular guaranteed order * * @return */ - public List getContactFeatures(String type) + public List getContactFeatures(String... type) { List result = new ArrayList(); - FeatureStore featureSet = featureStore.get(type); - if (featureSet != null) + + for (String featureType : varargToTypes(type)) { - result.addAll(featureSet.getContactFeatures()); + FeatureStore featureSet = featureStore.get(featureType); + if (featureSet != null) + { + result.addAll(featureSet.getContactFeatures()); + } } return result; } /** - * Answers a list of all non-positional features of the given type, in no - * particular guaranteed order + * Answers a list of all non-positional features, optionally restricted to + * specified types, in no particular guaranteed order * + * @param type + * if no type is specified, all are returned * @return */ - public List getNonPositionalFeatures(String type) + public List getNonPositionalFeatures(String... type) { List result = new ArrayList(); - FeatureStore featureSet = featureStore.get(type); - if (featureSet != null) + + for (String featureType : varargToTypes(type)) { - result.addAll(featureSet.getNonPositionalFeatures()); + FeatureStore featureSet = featureStore.get(featureType); + if (featureSet != null) + { + result.addAll(featureSet.getNonPositionalFeatures()); + } } return result; } @@ -246,19 +219,31 @@ public class SequenceFeatures /** * Returns a set of the distinct feature groups present in the collection. The - * set may include null. The parameter determines whether the groups for - * positional or for non-positional features are returned. + * set may include null. The boolean parameter determines whether the groups + * for positional or for non-positional features are returned. The optional + * type parameter may be used to restrict to groups for specified feature + * types. * * @param positionalFeatures + * @param type * @return */ - public Set getFeatureGroups(boolean positionalFeatures) + public Set getFeatureGroups(boolean positionalFeatures, + String... type) { Set groups = new HashSet(); - for (FeatureStore featureSet : featureStore.values()) + + Iterable types = varargToTypes(type); + + for (String featureType : types) { - groups.addAll(featureSet.getFeatureGroups(positionalFeatures)); + FeatureStore featureSet = featureStore.get(featureType); + if (featureSet != null) + { + groups.addAll(featureSet.getFeatureGroups(positionalFeatures)); + } } + return groups; } @@ -276,6 +261,7 @@ public class SequenceFeatures String... groups) { Set result = new HashSet(); + for (Entry featureType : featureStore.entrySet()) { Set featureGroups = featureType.getValue().getFeatureGroups(