X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FMapList.java;h=58abdc3926c1bf1badddf8e83e4b0724c06b30da;hb=37de9310bec3501cbc6381e0c3dcb282fcaad812;hp=ab811a93d6659d3e758535690a8790dc91ffd501;hpb=9c39e96af6b84257604da448101505361dced686;p=jalview.git diff --git a/src/jalview/util/MapList.java b/src/jalview/util/MapList.java index ab811a9..58abdc3 100644 --- a/src/jalview/util/MapList.java +++ b/src/jalview/util/MapList.java @@ -88,8 +88,6 @@ public class MapList @Override public boolean equals(Object o) { - // TODO should also override hashCode to ensure equal objects have equal - // hashcodes if (o == null || !(o instanceof MapList)) { return false; @@ -112,6 +110,19 @@ public class MapList } /** + * Returns a hashcode made from the fromRatio, toRatio, and from/to ranges + */ + @Override + public int hashCode() + { + int hashCode = 31 * fromRatio; + hashCode = 31 * hashCode + toRatio; + hashCode = 31 * hashCode + fromShifts.toArray().hashCode(); + hashCode = 31 * hashCode + toShifts.toArray().hashCode(); + return hashCode; + } + + /** * Returns the 'from' ranges as {[start1, end1], [start2, end2], ...} * * @return @@ -331,7 +342,8 @@ public class MapList */ public static List coalesceRanges(final List ranges) { - if (ranges == null || ranges.size() < 2) { + if (ranges == null || ranges.size() < 2) + { return ranges; } @@ -342,7 +354,7 @@ public class MapList lastRange = new int[] { lastRange[0], lastRange[1] }; merged.add(lastRange); boolean first = true; - + for (final int[] range : ranges) { if (first) @@ -376,7 +388,8 @@ public class MapList * if next range is in the same direction as last and contiguous, * just update the end position of the last range */ - boolean sameDirection = range[1] == range[0] || direction == lastDirection; + boolean sameDirection = range[1] == range[0] + || direction == lastDirection; boolean extending = range[0] == lastRange[1] + lastDirection; boolean overlapping = (lastDirection == 1 && range[0] >= lastRange[0] && range[0] <= lastRange[1]) || (lastDirection == -1 && range[0] <= lastRange[0] && range[0] >= lastRange[1]); @@ -393,7 +406,7 @@ public class MapList lastDirection = (range[1] == range[0]) ? lastDirection : direction; } } - + return changed ? merged : ranges; } @@ -992,6 +1005,10 @@ public class MapList */ public void addMapList(MapList map) { + if (this.equals(map)) + { + return; + } this.fromLowest = Math.min(fromLowest, map.fromLowest); this.toLowest = Math.min(toLowest, map.toLowest); this.fromHighest = Math.max(fromHighest, map.fromHighest); @@ -1087,4 +1104,15 @@ public class MapList } return forwardStrand; } + + /** + * + * @return true if from, or to is a three to 1 mapping + */ + public boolean isTripletMap() + { + return (toRatio == 3 && fromRatio == 1) + || (fromRatio == 3 && toRatio == 1); + } + }