X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FSequenceFeature.java;h=f17bd3349604541fd923c9da101bf16e77abea80;hb=bab4b08733a9543bdce5c0b9d1c32ca7d18ad9e3;hp=25dfc409b232e8bb691f7b63ec9bb642d519614a;hpb=4e77a2d1581819e35ba9e186324c522f1e4b0a25;p=jalview.git diff --git a/src/jalview/datamodel/SequenceFeature.java b/src/jalview/datamodel/SequenceFeature.java index 25dfc40..f17bd33 100755 --- a/src/jalview/datamodel/SequenceFeature.java +++ b/src/jalview/datamodel/SequenceFeature.java @@ -22,6 +22,7 @@ package jalview.datamodel; import jalview.datamodel.features.FeatureLocationI; +import java.util.Comparator; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -58,7 +59,7 @@ public class SequenceFeature implements FeatureLocationI private static final String ATTRIBUTES = "ATTRIBUTES"; /* - * type, begin, end, featureGroup and contactFeature are final + * type, begin, end, featureGroup, score and contactFeature are final * to ensure that the integrity of SequenceFeatures data store * can't be broken by direct update of these fields */ @@ -143,20 +144,21 @@ public class SequenceFeature implements FeatureLocationI * A copy constructor that allows the value of final fields to be 'modified' * * @param sf + * @param newType * @param newBegin * @param newEnd * @param newGroup * @param newScore */ - public SequenceFeature(SequenceFeature sf, int newBegin, int newEnd, - String newGroup, float newScore) + public SequenceFeature(SequenceFeature sf, String newType, int newBegin, + int newEnd, String newGroup, float newScore) { - this(sf.getType(), sf.getDescription(), newBegin, newEnd, newScore, + this(newType, sf.getDescription(), newBegin, newEnd, newScore, newGroup); if (sf.otherDetails != null) { - otherDetails = new HashMap(); + otherDetails = new HashMap<>(); for (Entry entry : sf.otherDetails.entrySet()) { otherDetails.put(entry.getKey(), entry.getValue()); @@ -164,7 +166,7 @@ public class SequenceFeature implements FeatureLocationI } if (sf.links != null && sf.links.size() > 0) { - links = new Vector(); + links = new Vector<>(); for (int i = 0, iSize = sf.links.size(); i < iSize; i++) { links.addElement(sf.links.elementAt(i)); @@ -173,6 +175,21 @@ public class SequenceFeature implements FeatureLocationI } /** + * A copy constructor that allows the value of final fields to be 'modified' + * + * @param sf + * @param newBegin + * @param newEnd + * @param newGroup + * @param newScore + */ + public SequenceFeature(SequenceFeature sf, int newBegin, int newEnd, + String newGroup, float newScore) + { + this(sf, sf.getType(), newBegin, newEnd, newGroup, newScore); + } + + /** * Two features are considered equal if they have the same type, group, * description, start, end, phase, strand, and (if present) 'Name', ID' and * 'Parent' attributes. @@ -217,8 +234,8 @@ public class SequenceFeature implements FeatureLocationI return false; } - if (!(type + description + featureGroup + getPhase()).equals(sf.type - + sf.description + sf.featureGroup + sf.getPhase())) + if (!(type + description + featureGroup + getPhase()).equals( + sf.type + sf.description + sf.featureGroup + sf.getPhase())) { return false; } @@ -316,7 +333,7 @@ public class SequenceFeature implements FeatureLocationI { if (links == null) { - links = new Vector(); + links = new Vector<>(); } if (!links.contains(labelLink)) @@ -378,7 +395,7 @@ public class SequenceFeature implements FeatureLocationI { if (otherDetails == null) { - otherDetails = new HashMap(); + otherDetails = new HashMap<>(); } otherDetails.put(key, value); @@ -520,3 +537,21 @@ public class SequenceFeature implements FeatureLocationI return begin == 0 && end == 0; } } + +class SFSortByEnd implements Comparator +{ + @Override + public int compare(SequenceFeature a, SequenceFeature b) + { + return a.getEnd() - b.getEnd(); + } +} + +class SFSortByBegin implements Comparator +{ + @Override + public int compare(SequenceFeature a, SequenceFeature b) + { + return a.getBegin() - b.getBegin(); + } +}