From 0d83689f1222cdf55789422e6528f25ffa24ffc2 Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 19 Feb 2010 09:24:11 +0000 Subject: [PATCH] formatting git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@516 be28352e-c001-0410-b1a7-c7978e42abec --- src/uk/ac/vamsas/objects/utils/MapList.java | 283 ++++++++++----------------- 1 file changed, 99 insertions(+), 184 deletions(-) diff --git a/src/uk/ac/vamsas/objects/utils/MapList.java b/src/uk/ac/vamsas/objects/utils/MapList.java index ab4e866..59d27a9 100644 --- a/src/uk/ac/vamsas/objects/utils/MapList.java +++ b/src/uk/ac/vamsas/objects/utils/MapList.java @@ -410,7 +410,7 @@ public class MapList { // inefficient implementation int fromStart[] = shiftTo(start); int fromEnd[] = shiftTo(end); // needs to be inclusive of end of symbol - // position + // position if (fromStart == null || fromEnd == null) return null; int iv[] = getIntervals(fromShifts, fromStart, fromEnd, fromRatio); @@ -458,65 +458,46 @@ public class MapList { int iv[], i = 0, fs = -1, fe_s = -1, fe = -1; // containing intervals // search intervals to locate ones containing startpos and count endindx // positions on from endpos - while (intv < intvSize && (fs == -1 || fe == -1)) - { + while (intv < intvSize && (fs == -1 || fe == -1)) { iv = (int[]) fromShifts2.elementAt(intv++); - if (fe_s > -1) - { + if (fe_s > -1) { endpos = iv[0]; // start counting from beginning of interval endindx--; // inclusive of endpos } - if (iv[0] <= iv[1]) - { - if (fs == -1 && startpos >= iv[0] && startpos <= iv[1]) - { + if (iv[0] <= iv[1]) { + if (fs == -1 && startpos >= iv[0] && startpos <= iv[1]) { fs = i; } - if (endpos >= iv[0] && endpos <= iv[1]) - { - if (fe_s == -1) - { + if (endpos >= iv[0] && endpos <= iv[1]) { + if (fe_s == -1) { fe_s = i; } - if (fe_s != -1) - { - if (endpos + endindx <= iv[1]) - { - fe = i; + if (fe_s != -1) { + if (endpos + endindx <= iv[1]) { + fe = i; endpos = endpos + endindx; // end of end token is within this - // interval - } - else - { + // interval + } else { endindx -= iv[1] - endpos; // skip all this interval too } } } - } - else - { - if (fs == -1 && startpos <= iv[0] && startpos >= iv[1]) - { + } else { + if (fs == -1 && startpos <= iv[0] && startpos >= iv[1]) { fs = i; } - if (endpos <= iv[0] && endpos >= iv[1]) - { - if (fe_s == -1) - { + if (endpos <= iv[0] && endpos >= iv[1]) { + if (fe_s == -1) { fe_s = i; } - if (fe_s != -1) - { - if (endpos - endindx >= iv[1]) - { - fe = i; + if (fe_s != -1) { + if (endpos - endindx >= iv[1]) { + fe = i; endpos = endpos - endindx; // end of end token is within this - // interval - } - else - { + // interval + } else { endindx -= endpos - iv[1]; // skip all this interval too - } + } } } } @@ -525,53 +506,41 @@ public class MapList { if (fs == fe && fe == -1) return null; Vector ranges = new Vector(); - if (fs <= fe) - { + if (fs <= fe) { intv = fs; i = fs; // truncate initial interval iv = (int[]) fromShifts2.elementAt(intv++); - iv = new int[] - { iv[0], iv[1] };// clone + iv = new int[] { iv[0], iv[1] };// clone if (i == fs) iv[0] = startpos; - while (i != fe) - { + while (i != fe) { ranges.addElement(iv); // add initial range iv = (int[]) fromShifts2.elementAt(intv++); // get next interval - iv = new int[] - { iv[0], iv[1] };// clone + iv = new int[] { iv[0], iv[1] };// clone i++; } if (i == fe) iv[1] = endpos; ranges.addElement(iv); // add only - or final range - } - else - { + } else { // walk from end of interval. i = fromShifts2.size() - 1; - while (i > fs) - { + while (i > fs) { i--; } iv = (int[]) fromShifts2.elementAt(i); - iv = new int[] - { iv[1], iv[0] };// reverse and clone + iv = new int[] { iv[1], iv[0] };// reverse and clone // truncate initial interval - if (i == fs) - { + if (i == fs) { iv[0] = startpos; } - while (--i != fe) - { // fix apparent logic bug when fe==-1 + while (--i != fe) { // fix apparent logic bug when fe==-1 ranges.addElement(iv); // add (truncated) reversed interval iv = (int[]) fromShifts2.elementAt(i); - iv = new int[] - { iv[1], iv[0] }; // reverse and clone + iv = new int[] { iv[1], iv[0] }; // reverse and clone } - if (i == fe) - { + if (i == fe) { // interval is already reversed iv[1] = endpos; } @@ -579,14 +548,12 @@ public class MapList { } // create array of start end intervals. int[] range = null; - if (ranges != null && ranges.size() > 0) - { + if (ranges != null && ranges.size() > 0) { range = new int[ranges.size() * 2]; intv = 0; intvSize = ranges.size(); i = 0; - while (intv < intvSize) - { + while (intv < intvSize) { iv = (int[]) ranges.elementAt(intv); range[i++] = iv[0]; range[i++] = iv[1]; @@ -657,33 +624,24 @@ public class MapList { * @param fromS * @param fromE */ - public static void testMap(MapList ml, int fromS, int fromE) - { - for (int from = 1; from <= 25; from++) - { + public static void testMap(MapList ml, int fromS, int fromE) { + for (int from = 1; from <= 25; from++) { int[] too = ml.shiftFrom(from); System.out.print("ShiftFrom(" + from + ")=="); - if (too == null) - { + if (too == null) { System.out.print("NaN\n"); - } - else - { + } else { System.out.print(too[0] + " % " + too[1] + " (" + too[2] + ")"); System.out.print("\t+--+\t"); int[] toofrom = ml.shiftTo(too[0]); - if (toofrom != null) - { - if (toofrom[0] != from) - { - System.err.println("Mapping not reflexive:" + from + " " - + too[0] + "->" + toofrom[0]); + if (toofrom != null) { + if (toofrom[0] != from) { + System.err.println("Mapping not reflexive:" + from + " " + too[0] + + "->" + toofrom[0]); } - System.out.println("ShiftTo(" + too[0] + ")==" + toofrom[0] - + " % " + toofrom[1] + " (" + toofrom[2] + ")"); - } - else - { + System.out.println("ShiftTo(" + too[0] + ")==" + toofrom[0] + " % " + + toofrom[1] + " (" + toofrom[2] + ")"); + } else { System.out.println("ShiftTo(" + too[0] + ")==" + "NaN! - not Bijective Mapping!"); } @@ -692,23 +650,16 @@ public class MapList { int mmap[][] = ml.makeFromMap(); System.out.println("FromMap : (" + mmap[0][0] + " " + mmap[0][1] + " " + mmap[0][2] + " " + mmap[0][3] + " "); - for (int i = 1; i <= mmap[1].length; i++) - { - if (mmap[1][i - 1] == -1) - { + for (int i = 1; i <= mmap[1].length; i++) { + if (mmap[1][i - 1] == -1) { System.out.print(i + "=XXX"); - } - else - { + } else { System.out.print(i + "=" + (mmap[0][2] + mmap[1][i - 1])); } - if (i % 20 == 0) - { + if (i % 20 == 0) { System.out.print("\n"); - } - else - { + } else { System.out.print(","); } } @@ -716,32 +667,23 @@ public class MapList { System.out.print("\nTest locateInFrom\n"); { int f = mmap[0][2], t = mmap[0][3]; - while (f <= t) - { + while (f <= t) { System.out.println("Range " + f + " to " + t); int rng[] = ml.locateInFrom(f, t); - if (rng != null) - { - for (int i = 0; i < rng.length; i++) - { + if (rng != null) { + for (int i = 0; i < rng.length; i++) { System.out.print(rng[i] + ((i % 2 == 0) ? "," : ";")); } - } - else - { + } else { System.out.println("No range!"); } System.out.print("\nReversed\n"); rng = ml.locateInFrom(t, f); - if (rng != null) - { - for (int i = 0; i < rng.length; i++) - { + if (rng != null) { + for (int i = 0; i < rng.length; i++) { System.out.print(rng[i] + ((i % 2 == 0) ? "," : ";")); } - } - else - { + } else { System.out.println("No range!"); } System.out.print("\n"); @@ -753,23 +695,16 @@ public class MapList { mmap = ml.makeToMap(); System.out.println("ToMap : (" + mmap[0][0] + " " + mmap[0][1] + " " + mmap[0][2] + " " + mmap[0][3] + " "); - for (int i = 1; i <= mmap[1].length; i++) - { - if (mmap[1][i - 1] == -1) - { + for (int i = 1; i <= mmap[1].length; i++) { + if (mmap[1][i - 1] == -1) { System.out.print(i + "=XXX"); - } - else - { + } else { System.out.print(i + "=" + (mmap[0][2] + mmap[1][i - 1])); } - if (i % 20 == 0) - { + if (i % 20 == 0) { System.out.print("\n"); - } - else - { + } else { System.out.print(","); } } @@ -778,32 +713,23 @@ public class MapList { System.out.print("\nTest locateInTo\n"); { int f = mmap[0][2], t = mmap[0][3]; - while (f <= t) - { + while (f <= t) { System.out.println("Range " + f + " to " + t); int rng[] = ml.locateInTo(f, t); - if (rng != null) - { - for (int i = 0; i < rng.length; i++) - { + if (rng != null) { + for (int i = 0; i < rng.length; i++) { System.out.print(rng[i] + ((i % 2 == 0) ? "," : ";")); } - } - else - { + } else { System.out.println("No range!"); } System.out.print("\nReversed\n"); rng = ml.locateInTo(t, f); - if (rng != null) - { - for (int i = 0; i < rng.length; i++) - { + if (rng != null) { + for (int i = 0; i < rng.length; i++) { System.out.print(rng[i] + ((i % 2 == 0) ? "," : ";")); } - } - else - { + } else { System.out.println("No range!"); } f++; @@ -814,26 +740,19 @@ public class MapList { } - public static void main(String argv[]) - { - MapList ml = new MapList(new int[] - { 1, 5, 10, 15, 25, 20 }, new int[] - { 51, 1 }, 1, 3); - MapList ml1 = new MapList(new int[] - { 1, 3, 17, 4 }, new int[] - { 51, 1 }, 1, 3); - MapList ml2 = new MapList(new int[] - { 1, 60 }, new int[] - { 1, 20 }, 3, 1); + public static void main(String argv[]) { + MapList ml = new MapList(new int[] { 1, 5, 10, 15, 25, 20 }, new int[] { + 51, 1 }, 1, 3); + MapList ml1 = new MapList(new int[] { 1, 3, 17, 4 }, new int[] { 51, 1 }, + 1, 3); + MapList ml2 = new MapList(new int[] { 1, 60 }, new int[] { 1, 20 }, 3, 1); // test internal consistency int to[] = new int[51]; MapList.testMap(ml, 1, 60); - MapList mldna = new MapList(new int[] - { 2, 2, 6, 8, 12, 16 }, new int[] - { 1, 3 }, 3, 1); + MapList mldna = new MapList(new int[] { 2, 2, 6, 8, 12, 16 }, new int[] { + 1, 3 }, 3, 1); int[] frm = mldna.locateInFrom(1, 1); - testLocateFrom(mldna, 1, 1, new int[] - { 2, 2, 6, 7 }); + testLocateFrom(mldna, 1, 1, new int[] { 2, 2, 6, 7 }); MapList.testMap(mldna, 1, 3); /* * for (int from=1; from<=51; from++) { int[] too=ml.shiftTo(from); int[] @@ -843,26 +762,20 @@ public class MapList { * +too[0]+")=="+toofrom[0]+" % "+toofrom[1]); } */ System.out.print("Success?\n"); // if we get here - something must be - // working! + // working! } - private static void testLocateFrom(MapList mldna, int i, int j, int[] ks) - { + private static void testLocateFrom(MapList mldna, int i, int j, int[] ks) { int[] frm = mldna.locateInFrom(i, j); - if (frm == ks || java.util.Arrays.equals(frm, ks)) - { + if (frm == ks || java.util.Arrays.equals(frm, ks)) { System.out.println("Success test locate from " + i + " to " + j); - } - else - { + } else { System.err.println("Failed test locate from " + i + " to " + j); - for (int c = 0; c < frm.length; c++) - { + for (int c = 0; c < frm.length; c++) { System.err.print(frm[c] + ((c % 2 == 0) ? "," : ";")); } System.err.println("Expected"); - for (int c = 0; c < ks.length; c++) - { + for (int c = 0; c < ks.length; c++) { System.err.print(ks[c] + ((c % 2 == 0) ? "," : ";")); } } @@ -873,26 +786,28 @@ public class MapList { * @return a MapList whose From range is this maplist's To Range, and vice * versa */ - public MapList getInverse() - { + public MapList getInverse() { return new MapList(getToRanges(), getFromRanges(), getToRatio(), getFromRatio()); } /** * test for containment rather than equivalence to another mapping - * @param map to be tested for containment - * @return true if local or mapped range map contains or is contained by this mapping + * + * @param map + * to be tested for containment + * @return true if local or mapped range map contains or is contained by this + * mapping */ - public boolean containsEither(boolean local, MapList map) - { - if (local) - { - return ((getFromLowest()>=map.getFromLowest() && getFromHighest()<=map.getFromHighest()) - || (getFromLowest()<=map.getFromLowest() && getFromHighest()>=map.getFromHighest())); + public boolean containsEither(boolean local, MapList map) { + if (local) { + return ((getFromLowest() >= map.getFromLowest() && getFromHighest() <= map + .getFromHighest()) || (getFromLowest() <= map.getFromLowest() && getFromHighest() >= map + .getFromHighest())); } else { - return ((getToLowest()>=map.getToLowest() && getToHighest()<=map.getToHighest()) - || (getToLowest()<=map.getToLowest() && getToHighest()>=map.getToHighest())); + return ((getToLowest() >= map.getToLowest() && getToHighest() <= map + .getToHighest()) || (getToLowest() <= map.getToLowest() && getToHighest() >= map + .getToHighest())); } } } -- 1.7.10.2