X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2Ffeatures%2FFeatureStore.java;h=84e77365e48e2daaa514c106344aaff3961a392b;hb=e6798fd04b1d7a35836a2e84deae5a94a35b88b9;hp=c6a49dbbc56b3a39d26cf26f3ea2080d23953d64;hpb=c8863c027ddace3961405ed0051f104f1ec99581;p=jalview.git diff --git a/src/jalview/datamodel/features/FeatureStore.java b/src/jalview/datamodel/features/FeatureStore.java index c6a49db..84e7736 100644 --- a/src/jalview/datamodel/features/FeatureStore.java +++ b/src/jalview/datamodel/features/FeatureStore.java @@ -1,5 +1,6 @@ package jalview.datamodel.features; +import jalview.datamodel.ContiguousI; import jalview.datamodel.SequenceFeature; import java.util.ArrayList; @@ -280,7 +281,7 @@ public class FeatureStore { if (nestedFeatures == null) { - nestedFeatures = new NCList(feature); + nestedFeatures = new NCList<>(feature); return true; } return nestedFeatures.add(feature, false); @@ -454,7 +455,7 @@ public class FeatureStore */ public List findOverlappingFeatures(long start, long end) { - List result = new ArrayList(); + List result = new ArrayList<>(); findNonNestedFeatures(start, end, result); @@ -632,7 +633,7 @@ public class FeatureStore /* * add non-nested features (may be all features for many cases) */ - List result = new ArrayList(); + List result = new ArrayList<>(); result.addAll(nonNestedFeatures); /* @@ -666,7 +667,7 @@ public class FeatureStore { return Collections.emptyList(); } - return new ArrayList(contactFeatureStarts); + return new ArrayList<>(contactFeatureStarts); } /** @@ -681,7 +682,7 @@ public class FeatureStore { return Collections.emptyList(); } - return new ArrayList(nonPositionalFeatures); + return new ArrayList<>(nonPositionalFeatures); } /** @@ -819,27 +820,6 @@ public class FeatureStore } /** - * Scans all positional features to check whether the given feature group is - * found, and returns true if found, else false - * - * @param featureGroup - * @return - */ - protected boolean findFeatureGroup(String featureGroup) - { - for (SequenceFeature sf : getPositionalFeatures()) - { - String group = sf.getFeatureGroup(); - if (group == featureGroup - || (group != null && group.equals(featureGroup))) - { - return true; - } - } - return false; - } - - /** * Answers true if this store has no features, else false * * @return @@ -992,7 +972,7 @@ public class FeatureStore public List getFeaturesForGroup(boolean positional, String group) { - List result = new ArrayList(); + List result = new ArrayList<>(); /* * if we know features don't include the target group, no need @@ -1017,4 +997,40 @@ public class FeatureStore } return result; } + + /** + * Adds the shift value to the start and end of all positional features. + * Returns true if at least one feature was updated, else false. + * + * @param shift + * @return + */ + public synchronized boolean shiftFeatures(int shift) + { + /* + * Because begin and end are final fields (to ensure the data store's + * integrity), we have to delete each feature and re-add it as amended. + * (Although a simple shift of all values would preserve data integrity!) + */ + boolean modified = false; + for (SequenceFeature sf : getPositionalFeatures()) + { + modified = true; + int newBegin = sf.getBegin() + shift; + int newEnd = sf.getEnd() + shift; + + /* + * sanity check: don't shift left of the first residue + */ + if (newEnd > 0) + { + newBegin = Math.max(1, newBegin); + SequenceFeature sf2 = new SequenceFeature(sf, newBegin, newEnd, + sf.getFeatureGroup(), sf.getScore()); + addFeature(sf2); + } + delete(sf); + } + return modified; + } }