From 81c319be6445aadda7c29045b37d6ee2ad26aa3e Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 13 Jul 2007 14:54:55 +0000 Subject: [PATCH] bugfix and comments --- src/jalview/util/MapList.java | 47 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/jalview/util/MapList.java b/src/jalview/util/MapList.java index 2464264..f67b47f 100644 --- a/src/jalview/util/MapList.java +++ b/src/jalview/util/MapList.java @@ -65,6 +65,33 @@ public class MapList public Vector toShifts; int fromRatio; // number of steps in fromShifts to one toRatio unit int toRatio; // number of steps in toShifts to one fromRatio + + /** + * + * @return series of intervals mapped in from + */ + public int[] getFromRanges() + { + return getRanges(fromShifts); + } + public int[] getToRanges() + { + return getRanges(toShifts); + } + + private int[] getRanges(Vector shifts) + { + int[] rnges = new int[2*shifts.size()]; + Enumeration e = shifts.elements(); + int i=0; + while (e.hasMoreElements()) + { + int r[] = (int[]) e.nextElement(); + rnges[i++] = r[0]; + rnges[i++] = r[1]; + } + return rnges; + } /** * lowest and highest value in the from Map */ @@ -73,10 +100,18 @@ public class MapList * lowest and highest value in the to Map */ int[] toRange=null; + /** + * + * @return length of mapped phrase in from + */ public int getFromRatio() { return fromRatio; } + /** + * + * @return length of mapped phrase in to + */ public int getToRatio() { return toRatio; @@ -507,9 +542,9 @@ public class MapList { iv[0] = startpos; } - while (i!=fe) { + while (--i!=fe) { // fix apparent logic bug when fe==-1 ranges.addElement(iv); // add (truncated) reversed interval - iv = (int[]) fromShifts2.elementAt(--i); + iv = (int[]) fromShifts2.elementAt(i); iv = new int[] { iv[1], iv[0] }; // reverse and clone } if (i==fe) { @@ -763,4 +798,12 @@ public int[] getMappedWord(int pos) { }*/ System.out.print("Success?\n"); // if we get here - something must be working! } + /** + * + * @return a MapList whose From range is this maplist's To Range, and vice versa + */ + public MapList getInverse() + { + return new MapList(getToRanges(), getFromRanges(), getToRatio(), getFromRatio()); + } } -- 1.7.10.2