1 Clazz.declarePackage ("jalview.util");
2 Clazz.load (["java.util.ArrayList"], "jalview.util.MapList", ["java.lang.StringBuilder", "java.util.Arrays"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.fromShifts = null;
12 Clazz.instantialize (this, arguments);
13 }, jalview.util, "MapList");
14 Clazz.prepareFields (c$, function () {
15 this.fromShifts = new java.util.ArrayList ();
16 this.toShifts = new java.util.ArrayList ();
18 Clazz.overrideMethod (c$, "equals",
20 if (o == null || !(Clazz.instanceOf (o, jalview.util.MapList))) {
25 }if (obj.fromRatio != this.fromRatio || obj.toRatio != this.toRatio || obj.fromShifts == null || obj.toShifts == null) {
27 }return java.util.Arrays.deepEquals (this.fromShifts.toArray (), obj.fromShifts.toArray ()) && java.util.Arrays.deepEquals (this.toShifts.toArray (), obj.toShifts.toArray ());
29 Clazz.defineMethod (c$, "getFromRanges",
31 return this.fromShifts;
33 Clazz.defineMethod (c$, "getToRanges",
37 c$.getRanges = Clazz.defineMethod (c$, "getRanges",
39 var rnges = Clazz.newIntArray (2 * shifts.size (), 0);
41 for (var r, $r = shifts.iterator (); $r.hasNext () && ((r = $r.next ()) || true);) {
47 Clazz.defineMethod (c$, "getFromRatio",
49 return this.fromRatio;
51 Clazz.defineMethod (c$, "getToRatio",
55 Clazz.defineMethod (c$, "getFromLowest",
57 return this.fromLowest;
59 Clazz.defineMethod (c$, "getFromHighest",
61 return this.fromHighest;
63 Clazz.defineMethod (c$, "getToLowest",
67 Clazz.defineMethod (c$, "getToHighest",
69 return this.toHighest;
71 Clazz.makeConstructor (c$,
72 function (from, to, fromRatio, toRatio) {
73 this.fromRatio = fromRatio;
74 this.toRatio = toRatio;
75 this.fromLowest = from[0];
76 this.fromHighest = from[1];
77 for (var i = 0; i < from.length; i += 2) {
78 this.fromLowest = Math.min (this.fromLowest, from[i]);
79 this.fromHighest = Math.max (this.fromHighest, from[i + 1]);
80 this.fromShifts.add ( Clazz.newIntArray (-1, [from[i], from[i + 1]]));
82 this.toLowest = to[0];
83 this.toHighest = to[1];
84 for (var i = 0; i < to.length; i += 2) {
85 this.toLowest = Math.min (this.toLowest, to[i]);
86 this.toHighest = Math.max (this.toHighest, to[i + 1]);
87 this.toShifts.add ( Clazz.newIntArray (-1, [to[i], to[i + 1]]));
90 Clazz.makeConstructor (c$,
92 this.fromLowest = map.fromLowest;
93 this.fromHighest = map.fromHighest;
94 this.toLowest = map.toLowest;
95 this.toHighest = map.toHighest;
96 this.fromRatio = map.fromRatio;
97 this.toRatio = map.toRatio;
98 if (map.fromShifts != null) {
99 for (var r, $r = map.fromShifts.iterator (); $r.hasNext () && ((r = $r.next ()) || true);) {
100 this.fromShifts.add ( Clazz.newIntArray (-1, [r[0], r[1]]));
102 }if (map.toShifts != null) {
103 for (var r, $r = map.toShifts.iterator (); $r.hasNext () && ((r = $r.next ()) || true);) {
104 this.toShifts.add ( Clazz.newIntArray (-1, [r[0], r[1]]));
106 }}, "jalview.util.MapList");
107 Clazz.makeConstructor (c$,
108 function (fromRange, toRange, fromRatio, toRatio) {
109 this.fromShifts = fromRange;
110 this.toShifts = toRange;
111 this.fromRatio = fromRatio;
112 this.toRatio = toRatio;
113 this.fromLowest = 2147483647;
114 this.fromHighest = 0;
115 for (var range, $range = fromRange.iterator (); $range.hasNext () && ((range = $range.next ()) || true);) {
116 this.fromLowest = Math.min (this.fromLowest, range[0]);
117 this.fromHighest = Math.max (this.fromHighest, range[1]);
119 this.toLowest = 2147483647;
121 for (var range, $range = toRange.iterator (); $range.hasNext () && ((range = $range.next ()) || true);) {
122 this.toLowest = Math.min (this.toLowest, range[0]);
123 this.toHighest = Math.max (this.toHighest, range[1]);
125 }, "java.util.List,java.util.List,~N,~N");
126 Clazz.defineMethod (c$, "makeFromMap",
128 return this.posMap (this.fromShifts, this.fromRatio, this.toShifts, this.toRatio);
130 Clazz.defineMethod (c$, "makeToMap",
132 return this.posMap (this.toShifts, this.toRatio, this.fromShifts, this.fromRatio);
134 Clazz.defineMethod (c$, "posMap",
135 ($fz = function (shiftTo, ratio, shiftFrom, toRatio) {
137 var ivSize = shiftTo.size ();
140 }var intv = shiftTo.get (iv++);
146 }while (iv < ivSize) {
147 intv = shiftTo.get (iv++);
148 if (intv[0] < from) {
150 }if (intv[1] < from) {
159 var mp = Clazz.newIntArray (to - from + 2, 0);
160 for (var i = 0; i < mp.length; i++) {
161 var m = jalview.util.MapList.shift (i + from, shiftTo, ratio, shiftFrom, toRatio);
172 var map = Clazz.newArray (-1, [ Clazz.newIntArray (-1, [from, to, tF, tT]), Clazz.newIntArray (to - from + 2, 0)]);
175 for (var i = 0; i < mp.length; i++) {
177 map[1][i] = mp[i][0] - tF;
182 }, $fz.isPrivate = true, $fz), "java.util.List,~N,java.util.List,~N");
183 Clazz.defineMethod (c$, "shiftFrom",
185 return jalview.util.MapList.shift (pos, this.fromShifts, this.fromRatio, this.toShifts, this.toRatio);
187 Clazz.defineMethod (c$, "shiftTo",
189 return jalview.util.MapList.shift (pos, this.toShifts, this.toRatio, this.fromShifts, this.fromRatio);
191 c$.shift = Clazz.defineMethod (c$, "shift",
192 function (pos, shiftTo, fromRatio, shiftFrom, toRatio) {
193 var fromCount = jalview.util.MapList.countPos (shiftTo, pos);
194 if (fromCount == null) {
196 }var fromRemainder = (fromCount[0] - 1) % fromRatio;
197 var toCount = 1 + ((Clazz.doubleToInt ((fromCount[0] - 1) / fromRatio)) * toRatio);
198 var toPos = jalview.util.MapList.countToPos (shiftFrom, toCount);
201 }return Clazz.newIntArray (-1, [toPos[0], fromRemainder, toPos[1]]);
202 }, "~N,java.util.List,~N,java.util.List,~N");
203 c$.countPos = Clazz.defineMethod (c$, "countPos",
204 function (shiftTo, pos) {
208 var ivSize = shiftTo.size ();
209 while (iv < ivSize) {
210 intv = shiftTo.get (iv++);
211 if (intv[0] <= intv[1]) {
212 if (pos >= intv[0] && pos <= intv[1]) {
213 return Clazz.newIntArray (-1, [count + pos - intv[0] + 1, 1]);
215 count += intv[1] - intv[0] + 1;
217 if (pos >= intv[1] && pos <= intv[0]) {
218 return Clazz.newIntArray (-1, [count + intv[0] - pos + 1, -1]);
220 count += intv[0] - intv[1] + 1;
223 }, "java.util.List,~N");
224 c$.countToPos = Clazz.defineMethod (c$, "countToPos",
225 function (shiftFrom, pos) {
229 var ivSize = shiftFrom.size ();
230 var intv = Clazz.newIntArray (-1, [0, 0]);
231 while (iv < ivSize) {
232 intv = shiftFrom.get (iv++);
233 diff = intv[1] - intv[0];
235 if (pos <= count + 1 + diff) {
236 return Clazz.newIntArray (-1, [pos - count - 1 + intv[0], 1]);
240 if (pos <= count + 1 - diff) {
241 return Clazz.newIntArray (-1, [intv[0] - (pos - count - 1), -1]);
246 }, "java.util.List,~N");
247 Clazz.defineMethod (c$, "locateInFrom",
248 function (start, end) {
249 var fromStart = this.shiftTo (start);
250 var fromEnd = this.shiftTo (end);
251 return jalview.util.MapList.getIntervals (this.fromShifts, fromStart, fromEnd, this.fromRatio);
253 Clazz.defineMethod (c$, "locateInTo",
254 function (start, end) {
255 var toStart = this.shiftFrom (start);
256 var toEnd = this.shiftFrom (end);
257 return jalview.util.MapList.getIntervals (this.toShifts, toStart, toEnd, this.toRatio);
259 c$.getIntervals = Clazz.defineMethod (c$, "getIntervals",
260 function (shiftFrom, fromStart, fromEnd, fromRatio2) {
261 if (fromStart == null || fromEnd == null) {
265 startpos = fromStart[0];
267 var endindx = (fromRatio2 - 1);
269 var intvSize = shiftFrom.size ();
275 while (intv < intvSize && (fs == -1 || fe == -1)) {
276 iv = shiftFrom.get (intv++);
280 }if (iv[0] <= iv[1]) {
281 if (fs == -1 && startpos >= iv[0] && startpos <= iv[1]) {
283 }if (endpos >= iv[0] && endpos <= iv[1]) {
287 if (endpos + endindx <= iv[1]) {
289 endpos = endpos + endindx;
291 endindx -= iv[1] - endpos;
293 if (fs == -1 && startpos <= iv[0] && startpos >= iv[1]) {
295 }if (endpos <= iv[0] && endpos >= iv[1]) {
299 if (endpos - endindx >= iv[1]) {
301 endpos = endpos - endindx;
303 endindx -= endpos - iv[1];
306 if (fs == fe && fe == -1) {
308 }var ranges = new java.util.ArrayList ();
312 iv = shiftFrom.get (intv++);
313 iv = Clazz.newIntArray (-1, [iv[0], iv[1]]);
318 iv = shiftFrom.get (intv++);
319 iv = Clazz.newIntArray (-1, [iv[0], iv[1]]);
326 i = shiftFrom.size () - 1;
330 iv = shiftFrom.get (i);
331 iv = Clazz.newIntArray (-1, [iv[1], iv[0]]);
336 iv = shiftFrom.get (i);
337 iv = Clazz.newIntArray (-1, [iv[1], iv[0]]);
343 if (ranges != null && ranges.size () > 0) {
344 range = Clazz.newIntArray (ranges.size () * 2, 0);
346 intvSize = ranges.size ();
348 while (intv < intvSize) {
349 iv = ranges.get (intv);
352 ranges.set (intv++, null);
355 }, "java.util.List,~A,~A,~N");
356 Clazz.defineMethod (c$, "getToPosition",
358 var mp = this.shiftTo (mpos);
363 Clazz.defineMethod (c$, "getToWord",
365 var mp = this.shiftTo (mpos);
367 return Clazz.newIntArray (-1, [mp[0], mp[0] + mp[2] * (this.getFromRatio () - 1)]);
370 Clazz.defineMethod (c$, "getMappedPosition",
372 var mp = this.shiftFrom (pos);
377 Clazz.defineMethod (c$, "getMappedWord",
379 var mp = this.shiftFrom (pos);
381 return Clazz.newIntArray (-1, [mp[0], mp[0] + mp[2] * (this.getToRatio () - 1)]);
384 Clazz.defineMethod (c$, "getInverse",
386 return new jalview.util.MapList (this.getToRanges (), this.getFromRanges (), this.getToRatio (), this.getFromRatio ());
388 Clazz.defineMethod (c$, "containsEither",
389 function (local, map) {
391 return ((this.getFromLowest () >= map.getFromLowest () && this.getFromHighest () <= map.getFromHighest ()) || (this.getFromLowest () <= map.getFromLowest () && this.getFromHighest () >= map.getFromHighest ()));
393 return ((this.getToLowest () >= map.getToLowest () && this.getToHighest () <= map.getToHighest ()) || (this.getToLowest () <= map.getToLowest () && this.getToHighest () >= map.getToHighest ()));
394 }}, "~B,jalview.util.MapList");
395 Clazz.overrideMethod (c$, "toString",
397 var sb = new StringBuilder (64);
398 sb.append ("From (").append (this.fromRatio).append (":").append (this.toRatio).append (") [");
399 for (var shift, $shift = this.fromShifts.iterator (); $shift.hasNext () && ((shift = $shift.next ()) || true);) {
400 sb.append (" ").append (java.util.Arrays.toString (shift));
402 sb.append (" ] To [");
403 for (var shift, $shift = this.toShifts.iterator (); $shift.hasNext () && ((shift = $shift.next ()) || true);) {
404 sb.append (" ").append (java.util.Arrays.toString (shift));
407 return sb.toString ();