Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / jalview / datamodel / SearchResults.js
1 Clazz.declarePackage ("jalview.datamodel");
2 Clazz.load (["java.util.ArrayList"], "jalview.datamodel.SearchResults", ["java.lang.StringBuilder", "java.util.Arrays"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.matches = null;
5 if (!Clazz.isClassDefined ("jalview.datamodel.SearchResults.Match")) {
6 jalview.datamodel.SearchResults.$SearchResults$Match$ ();
7 }
8 Clazz.instantialize (this, arguments);
9 }, jalview.datamodel, "SearchResults");
10 Clazz.prepareFields (c$, function () {
11 this.matches =  new java.util.ArrayList ();
12 });
13 Clazz.defineMethod (c$, "addResult", 
14 function (seq, start, end) {
15 this.matches.add (Clazz.innerTypeInstance (jalview.datamodel.SearchResults.Match, this, null, seq, start, end));
16 }, "jalview.datamodel.SequenceI,~N,~N");
17 Clazz.defineMethod (c$, "involvesSequence", 
18 function (sequence) {
19 var ds = sequence.getDatasetSequence ();
20 for (var m, $m = this.matches.iterator (); $m.hasNext () && ((m = $m.next ()) || true);) {
21 if (m.sequence != null && (m.sequence === sequence || m.sequence === ds)) {
22 return true;
23 }}
24 return false;
25 }, "jalview.datamodel.SequenceI");
26 Clazz.defineMethod (c$, "getResults", 
27 function (sequence, start, end) {
28 if (this.matches.isEmpty ()) {
29 return null;
30 }var result = null;
31 var tmp = null;
32 var resultLength;
33 var matchStart = 0;
34 var matchEnd = 0;
35 var mfound;
36 for (var m, $m = this.matches.iterator (); $m.hasNext () && ((m = $m.next ()) || true);) {
37 mfound = false;
38 if (m.sequence === sequence) {
39 mfound = true;
40 matchStart = sequence.findIndex (m.start) - 1;
41 matchEnd = sequence.findIndex (m.end) - 1;
42 } else if (m.sequence === sequence.getDatasetSequence ()) {
43 mfound = true;
44 matchStart = sequence.findIndex (m.start) - 1;
45 matchEnd = sequence.findIndex (m.end) - 1;
46 }if (mfound) {
47 if (matchStart <= end && matchEnd >= start) {
48 if (matchStart < start) {
49 matchStart = start;
50 }if (matchEnd > end) {
51 matchEnd = end;
52 }if (result == null) {
53 result =  Clazz.newIntArray (-1, [matchStart, matchEnd]);
54 } else {
55 resultLength = result.length;
56 tmp =  Clazz.newIntArray (resultLength + 2, 0);
57 System.arraycopy (result, 0, tmp, 0, resultLength);
58 result = tmp;
59 result[resultLength] = matchStart;
60 result[resultLength + 1] = matchEnd;
61 }} else {
62 }}}
63 return result;
64 }, "jalview.datamodel.SequenceI,~N,~N");
65 Clazz.defineMethod (c$, "getSize", 
66 function () {
67 return this.matches.size ();
68 });
69 Clazz.defineMethod (c$, "getResultSequence", 
70 function (index) {
71 return this.matches.get (index).sequence;
72 }, "~N");
73 Clazz.defineMethod (c$, "getResultStart", 
74 function (i) {
75 return this.matches.get (i).start;
76 }, "~N");
77 Clazz.defineMethod (c$, "getResultEnd", 
78 function (i) {
79 return this.matches.get (i).end;
80 }, "~N");
81 Clazz.defineMethod (c$, "isEmpty", 
82 function () {
83 return this.matches.isEmpty ();
84 });
85 Clazz.defineMethod (c$, "getResults", 
86 function () {
87 return this.matches;
88 });
89 Clazz.overrideMethod (c$, "toString", 
90 function () {
91 var result =  new StringBuilder (256);
92 for (var m, $m = this.matches.iterator (); $m.hasNext () && ((m = $m.next ()) || true);) {
93 result.append (m.toString ());
94 }
95 return result.toString ();
96 });
97 c$.$SearchResults$Match$ = function () {
98 Clazz.pu$h(self.c$);
99 c$ = Clazz.decorateAsClass (function () {
100 Clazz.prepareCallback (this, arguments);
101 this.sequence = null;
102 this.start = 0;
103 this.end = 0;
104 Clazz.instantialize (this, arguments);
105 }, jalview.datamodel.SearchResults, "Match");
106 Clazz.makeConstructor (c$, 
107 function (a, b, c) {
108 this.sequence = a;
109 this.start = b;
110 this.end = c;
111 }, "jalview.datamodel.SequenceI,~N,~N");
112 Clazz.defineMethod (c$, "getSequence", 
113 function () {
114 return this.sequence;
115 });
116 Clazz.defineMethod (c$, "getStart", 
117 function () {
118 return this.start;
119 });
120 Clazz.defineMethod (c$, "getEnd", 
121 function () {
122 return this.end;
123 });
124 Clazz.overrideMethod (c$, "toString", 
125 function () {
126 var a = this.sequence.getSequence ();
127 var b = Math.max (this.start - 1, 0);
128 var c = Math.min (this.end, a.length + 1);
129 return String.valueOf (java.util.Arrays.copyOfRange (a, b, c));
130 });
131 Clazz.defineMethod (c$, "setSequence", 
132 function (a) {
133 this.sequence = a;
134 }, "jalview.datamodel.SequenceI");
135 c$ = Clazz.p0p ();
136 };
137 });