Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would implement <code>search</code> as follows - </p> <pre><code>public static List&lt;Interval&gt; search( String searchText, String[][] data) { List&lt;Interval&gt; al = new ArrayList&lt;&gt;(); if (searchText != null) { searchText = searchText.trim().toUpperCase(); char[] toMatch = searchText.toCharArray(); for (int i = 0; i &lt; data.length; i++) { if (data[i] != null &amp;&amp; data.length &gt; i &amp;&amp; data[i].length &gt; 0 &amp;&amp; data[i][0].charAt(0) == toMatch[0]) { boolean matched = true; for (int t = 1; t &lt; toMatch.length; t++) { if (i + t &gt; data.length || data[i + t][0].charAt(0) != toMatch[t]) { i += (t - 1); matched = false; break; } } if (matched) { Interval interval = new Interval(); interval.start = i - 1; interval.end = interval.start + (toMatch.length - 1); al.add(interval); } } } } return al; } </code></pre> <p>And, I would modify <code>Interval</code> to add a <code>toString()</code> like this</p> <pre><code>public String toString() { return String.valueOf(start) + "-" + end; } </code></pre> <p>Finally, to test it I would use this main method.</p> <pre><code>public static void main(String[] args) { String[][] test = { { "N" }, { "A" }, { "N" }, { "A" }, { "T" }, { "A" }, { "N" }, { "E" }, { "X" }, { "T" }, { "E" }, { "R" }, { "N" }, { "B" }, { "N" }, { "E" }, { "X" }, { "T" } }; List&lt;Interval&gt; al = search("next", test); for (Interval i : al) { System.out.println(i); } } </code></pre> <p>And I did receive this output -</p> <pre><code>5-8 13-16 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload