// inefficient implementation\r
int fromStart[] = shiftTo(start);\r
int fromEnd[] = shiftTo(end); // needs to be inclusive of end of symbol\r
- // position\r
+ // position\r
if (fromStart == null || fromEnd == null)\r
return null;\r
int iv[] = getIntervals(fromShifts, fromStart, fromEnd, fromRatio);\r
int iv[], i = 0, fs = -1, fe_s = -1, fe = -1; // containing intervals\r
// search intervals to locate ones containing startpos and count endindx\r
// positions on from endpos\r
- while (intv < intvSize && (fs == -1 || fe == -1))\r
- {\r
+ while (intv < intvSize && (fs == -1 || fe == -1)) {\r
iv = (int[]) fromShifts2.elementAt(intv++);\r
- if (fe_s > -1)\r
- {\r
+ if (fe_s > -1) {\r
endpos = iv[0]; // start counting from beginning of interval\r
endindx--; // inclusive of endpos\r
}\r
- if (iv[0] <= iv[1])\r
- {\r
- if (fs == -1 && startpos >= iv[0] && startpos <= iv[1])\r
- {\r
+ if (iv[0] <= iv[1]) {\r
+ if (fs == -1 && startpos >= iv[0] && startpos <= iv[1]) {\r
fs = i;\r
}\r
- if (endpos >= iv[0] && endpos <= iv[1])\r
- {\r
- if (fe_s == -1)\r
- {\r
+ if (endpos >= iv[0] && endpos <= iv[1]) {\r
+ if (fe_s == -1) {\r
fe_s = i;\r
}\r
- if (fe_s != -1)\r
- {\r
- if (endpos + endindx <= iv[1])\r
- {\r
- fe = i;\r
+ if (fe_s != -1) {\r
+ if (endpos + endindx <= iv[1]) {\r
+ fe = i;\r
endpos = endpos + endindx; // end of end token is within this\r
- // interval\r
- }\r
- else\r
- {\r
+ // interval\r
+ } else {\r
endindx -= iv[1] - endpos; // skip all this interval too\r
}\r
}\r
}\r
- }\r
- else\r
- {\r
- if (fs == -1 && startpos <= iv[0] && startpos >= iv[1])\r
- {\r
+ } else {\r
+ if (fs == -1 && startpos <= iv[0] && startpos >= iv[1]) {\r
fs = i;\r
}\r
- if (endpos <= iv[0] && endpos >= iv[1])\r
- {\r
- if (fe_s == -1)\r
- {\r
+ if (endpos <= iv[0] && endpos >= iv[1]) {\r
+ if (fe_s == -1) {\r
fe_s = i;\r
}\r
- if (fe_s != -1)\r
- {\r
- if (endpos - endindx >= iv[1])\r
- {\r
- fe = i;\r
+ if (fe_s != -1) {\r
+ if (endpos - endindx >= iv[1]) {\r
+ fe = i;\r
endpos = endpos - endindx; // end of end token is within this\r
- // interval\r
- }\r
- else\r
- {\r
+ // interval\r
+ } else {\r
endindx -= endpos - iv[1]; // skip all this interval too\r
- }\r
+ }\r
}\r
}\r
}\r
if (fs == fe && fe == -1)\r
return null;\r
Vector ranges = new Vector();\r
- if (fs <= fe)\r
- {\r
+ if (fs <= fe) {\r
intv = fs;\r
i = fs;\r
// truncate initial interval\r
iv = (int[]) fromShifts2.elementAt(intv++);\r
- iv = new int[]\r
- { iv[0], iv[1] };// clone\r
+ iv = new int[] { iv[0], iv[1] };// clone\r
if (i == fs)\r
iv[0] = startpos;\r
- while (i != fe)\r
- {\r
+ while (i != fe) {\r
ranges.addElement(iv); // add initial range\r
iv = (int[]) fromShifts2.elementAt(intv++); // get next interval\r
- iv = new int[]\r
- { iv[0], iv[1] };// clone\r
+ iv = new int[] { iv[0], iv[1] };// clone\r
i++;\r
}\r
if (i == fe)\r
iv[1] = endpos;\r
ranges.addElement(iv); // add only - or final range\r
- }\r
- else\r
- {\r
+ } else {\r
// walk from end of interval.\r
i = fromShifts2.size() - 1;\r
- while (i > fs)\r
- {\r
+ while (i > fs) {\r
i--;\r
}\r
iv = (int[]) fromShifts2.elementAt(i);\r
- iv = new int[]\r
- { iv[1], iv[0] };// reverse and clone\r
+ iv = new int[] { iv[1], iv[0] };// reverse and clone\r
// truncate initial interval\r
- if (i == fs)\r
- {\r
+ if (i == fs) {\r
iv[0] = startpos;\r
}\r
- while (--i != fe)\r
- { // fix apparent logic bug when fe==-1\r
+ while (--i != fe) { // fix apparent logic bug when fe==-1\r
ranges.addElement(iv); // add (truncated) reversed interval\r
iv = (int[]) fromShifts2.elementAt(i);\r
- iv = new int[]\r
- { iv[1], iv[0] }; // reverse and clone\r
+ iv = new int[] { iv[1], iv[0] }; // reverse and clone\r
}\r
- if (i == fe)\r
- {\r
+ if (i == fe) {\r
// interval is already reversed\r
iv[1] = endpos;\r
}\r
}\r
// create array of start end intervals.\r
int[] range = null;\r
- if (ranges != null && ranges.size() > 0)\r
- {\r
+ if (ranges != null && ranges.size() > 0) {\r
range = new int[ranges.size() * 2];\r
intv = 0;\r
intvSize = ranges.size();\r
i = 0;\r
- while (intv < intvSize)\r
- {\r
+ while (intv < intvSize) {\r
iv = (int[]) ranges.elementAt(intv);\r
range[i++] = iv[0];\r
range[i++] = iv[1];\r
* @param fromS\r
* @param fromE\r
*/\r
- public static void testMap(MapList ml, int fromS, int fromE)\r
- {\r
- for (int from = 1; from <= 25; from++)\r
- {\r
+ public static void testMap(MapList ml, int fromS, int fromE) {\r
+ for (int from = 1; from <= 25; from++) {\r
int[] too = ml.shiftFrom(from);\r
System.out.print("ShiftFrom(" + from + ")==");\r
- if (too == null)\r
- {\r
+ if (too == null) {\r
System.out.print("NaN\n");\r
- }\r
- else\r
- {\r
+ } else {\r
System.out.print(too[0] + " % " + too[1] + " (" + too[2] + ")");\r
System.out.print("\t+--+\t");\r
int[] toofrom = ml.shiftTo(too[0]);\r
- if (toofrom != null)\r
- {\r
- if (toofrom[0] != from)\r
- {\r
- System.err.println("Mapping not reflexive:" + from + " "\r
- + too[0] + "->" + toofrom[0]);\r
+ if (toofrom != null) {\r
+ if (toofrom[0] != from) {\r
+ System.err.println("Mapping not reflexive:" + from + " " + too[0]\r
+ + "->" + toofrom[0]);\r
}\r
- System.out.println("ShiftTo(" + too[0] + ")==" + toofrom[0]\r
- + " % " + toofrom[1] + " (" + toofrom[2] + ")");\r
- }\r
- else\r
- {\r
+ System.out.println("ShiftTo(" + too[0] + ")==" + toofrom[0] + " % "\r
+ + toofrom[1] + " (" + toofrom[2] + ")");\r
+ } else {\r
System.out.println("ShiftTo(" + too[0] + ")=="\r
+ "NaN! - not Bijective Mapping!");\r
}\r
int mmap[][] = ml.makeFromMap();\r
System.out.println("FromMap : (" + mmap[0][0] + " " + mmap[0][1] + " "\r
+ mmap[0][2] + " " + mmap[0][3] + " ");\r
- for (int i = 1; i <= mmap[1].length; i++)\r
- {\r
- if (mmap[1][i - 1] == -1)\r
- {\r
+ for (int i = 1; i <= mmap[1].length; i++) {\r
+ if (mmap[1][i - 1] == -1) {\r
System.out.print(i + "=XXX");\r
\r
- }\r
- else\r
- {\r
+ } else {\r
System.out.print(i + "=" + (mmap[0][2] + mmap[1][i - 1]));\r
}\r
- if (i % 20 == 0)\r
- {\r
+ if (i % 20 == 0) {\r
System.out.print("\n");\r
- }\r
- else\r
- {\r
+ } else {\r
System.out.print(",");\r
}\r
}\r
System.out.print("\nTest locateInFrom\n");\r
{\r
int f = mmap[0][2], t = mmap[0][3];\r
- while (f <= t)\r
- {\r
+ while (f <= t) {\r
System.out.println("Range " + f + " to " + t);\r
int rng[] = ml.locateInFrom(f, t);\r
- if (rng != null)\r
- {\r
- for (int i = 0; i < rng.length; i++)\r
- {\r
+ if (rng != null) {\r
+ for (int i = 0; i < rng.length; i++) {\r
System.out.print(rng[i] + ((i % 2 == 0) ? "," : ";"));\r
}\r
- }\r
- else\r
- {\r
+ } else {\r
System.out.println("No range!");\r
}\r
System.out.print("\nReversed\n");\r
rng = ml.locateInFrom(t, f);\r
- if (rng != null)\r
- {\r
- for (int i = 0; i < rng.length; i++)\r
- {\r
+ if (rng != null) {\r
+ for (int i = 0; i < rng.length; i++) {\r
System.out.print(rng[i] + ((i % 2 == 0) ? "," : ";"));\r
}\r
- }\r
- else\r
- {\r
+ } else {\r
System.out.println("No range!");\r
}\r
System.out.print("\n");\r
mmap = ml.makeToMap();\r
System.out.println("ToMap : (" + mmap[0][0] + " " + mmap[0][1] + " "\r
+ mmap[0][2] + " " + mmap[0][3] + " ");\r
- for (int i = 1; i <= mmap[1].length; i++)\r
- {\r
- if (mmap[1][i - 1] == -1)\r
- {\r
+ for (int i = 1; i <= mmap[1].length; i++) {\r
+ if (mmap[1][i - 1] == -1) {\r
System.out.print(i + "=XXX");\r
\r
- }\r
- else\r
- {\r
+ } else {\r
System.out.print(i + "=" + (mmap[0][2] + mmap[1][i - 1]));\r
}\r
- if (i % 20 == 0)\r
- {\r
+ if (i % 20 == 0) {\r
System.out.print("\n");\r
- }\r
- else\r
- {\r
+ } else {\r
System.out.print(",");\r
}\r
}\r
System.out.print("\nTest locateInTo\n");\r
{\r
int f = mmap[0][2], t = mmap[0][3];\r
- while (f <= t)\r
- {\r
+ while (f <= t) {\r
System.out.println("Range " + f + " to " + t);\r
int rng[] = ml.locateInTo(f, t);\r
- if (rng != null)\r
- {\r
- for (int i = 0; i < rng.length; i++)\r
- {\r
+ if (rng != null) {\r
+ for (int i = 0; i < rng.length; i++) {\r
System.out.print(rng[i] + ((i % 2 == 0) ? "," : ";"));\r
}\r
- }\r
- else\r
- {\r
+ } else {\r
System.out.println("No range!");\r
}\r
System.out.print("\nReversed\n");\r
rng = ml.locateInTo(t, f);\r
- if (rng != null)\r
- {\r
- for (int i = 0; i < rng.length; i++)\r
- {\r
+ if (rng != null) {\r
+ for (int i = 0; i < rng.length; i++) {\r
System.out.print(rng[i] + ((i % 2 == 0) ? "," : ";"));\r
}\r
- }\r
- else\r
- {\r
+ } else {\r
System.out.println("No range!");\r
}\r
f++;\r
\r
}\r
\r
- public static void main(String argv[])\r
- {\r
- MapList ml = new MapList(new int[]\r
- { 1, 5, 10, 15, 25, 20 }, new int[]\r
- { 51, 1 }, 1, 3);\r
- MapList ml1 = new MapList(new int[]\r
- { 1, 3, 17, 4 }, new int[]\r
- { 51, 1 }, 1, 3);\r
- MapList ml2 = new MapList(new int[]\r
- { 1, 60 }, new int[]\r
- { 1, 20 }, 3, 1);\r
+ public static void main(String argv[]) {\r
+ MapList ml = new MapList(new int[] { 1, 5, 10, 15, 25, 20 }, new int[] {\r
+ 51, 1 }, 1, 3);\r
+ MapList ml1 = new MapList(new int[] { 1, 3, 17, 4 }, new int[] { 51, 1 },\r
+ 1, 3);\r
+ MapList ml2 = new MapList(new int[] { 1, 60 }, new int[] { 1, 20 }, 3, 1);\r
// test internal consistency\r
int to[] = new int[51];\r
MapList.testMap(ml, 1, 60);\r
- MapList mldna = new MapList(new int[]\r
- { 2, 2, 6, 8, 12, 16 }, new int[]\r
- { 1, 3 }, 3, 1);\r
+ MapList mldna = new MapList(new int[] { 2, 2, 6, 8, 12, 16 }, new int[] {\r
+ 1, 3 }, 3, 1);\r
int[] frm = mldna.locateInFrom(1, 1);\r
- testLocateFrom(mldna, 1, 1, new int[]\r
- { 2, 2, 6, 7 });\r
+ testLocateFrom(mldna, 1, 1, new int[] { 2, 2, 6, 7 });\r
MapList.testMap(mldna, 1, 3);\r
/*\r
* for (int from=1; from<=51; from++) { int[] too=ml.shiftTo(from); int[]\r
* +too[0]+")=="+toofrom[0]+" % "+toofrom[1]); }\r
*/\r
System.out.print("Success?\n"); // if we get here - something must be\r
- // working!\r
+ // working!\r
}\r
\r
- private static void testLocateFrom(MapList mldna, int i, int j, int[] ks)\r
- {\r
+ private static void testLocateFrom(MapList mldna, int i, int j, int[] ks) {\r
int[] frm = mldna.locateInFrom(i, j);\r
- if (frm == ks || java.util.Arrays.equals(frm, ks))\r
- {\r
+ if (frm == ks || java.util.Arrays.equals(frm, ks)) {\r
System.out.println("Success test locate from " + i + " to " + j);\r
- }\r
- else\r
- {\r
+ } else {\r
System.err.println("Failed test locate from " + i + " to " + j);\r
- for (int c = 0; c < frm.length; c++)\r
- {\r
+ for (int c = 0; c < frm.length; c++) {\r
System.err.print(frm[c] + ((c % 2 == 0) ? "," : ";"));\r
}\r
System.err.println("Expected");\r
- for (int c = 0; c < ks.length; c++)\r
- {\r
+ for (int c = 0; c < ks.length; c++) {\r
System.err.print(ks[c] + ((c % 2 == 0) ? "," : ";"));\r
}\r
}\r
* @return a MapList whose From range is this maplist's To Range, and vice\r
* versa\r
*/\r
- public MapList getInverse()\r
- {\r
+ public MapList getInverse() {\r
return new MapList(getToRanges(), getFromRanges(), getToRatio(),\r
getFromRatio());\r
}\r
\r
/**\r
* test for containment rather than equivalence to another mapping\r
- * @param map to be tested for containment\r
- * @return true if local or mapped range map contains or is contained by this mapping \r
+ * \r
+ * @param map\r
+ * to be tested for containment\r
+ * @return true if local or mapped range map contains or is contained by this\r
+ * mapping\r
*/\r
- public boolean containsEither(boolean local, MapList map)\r
- {\r
- if (local)\r
- {\r
- return ((getFromLowest()>=map.getFromLowest() && getFromHighest()<=map.getFromHighest())\r
- || (getFromLowest()<=map.getFromLowest() && getFromHighest()>=map.getFromHighest()));\r
+ public boolean containsEither(boolean local, MapList map) {\r
+ if (local) {\r
+ return ((getFromLowest() >= map.getFromLowest() && getFromHighest() <= map\r
+ .getFromHighest()) || (getFromLowest() <= map.getFromLowest() && getFromHighest() >= map\r
+ .getFromHighest()));\r
} else {\r
- return ((getToLowest()>=map.getToLowest() && getToHighest()<=map.getToHighest())\r
- || (getToLowest()<=map.getToLowest() && getToHighest()>=map.getToHighest()));\r
+ return ((getToLowest() >= map.getToLowest() && getToHighest() <= map\r
+ .getToHighest()) || (getToLowest() <= map.getToLowest() && getToHighest() >= map\r
+ .getToHighest()));\r
}\r
}\r
}\r