Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A few comments;</p> <ul> <li>You only highlight the <em>first</em> occurance of the search string.</li> <li>You assume that lower case matching is fine. Unless this was specified as a requirement it might be better to provide two methods, one that respects case and one that ignores case.</li> <li>I would probably check the given parameters and throw a NPE if either of them were null. This would be the first thing my method did. I would clearly document this behaviour in the javadoc.</li> <li>Your method mame is bad; <code>findSubstringInQuery</code>'s main task isn't to find, it is to highlight and the <code>inQuery</code> part is superflous. Just call the method <code>highlight</code> or maybe <code>highlightIgnoreCase</code> if you are going to have a <code>highlight</code> that respects case.</li> <li>Your method parameter names are bad. I've looked at your method signature 10 times and still have to look at the method body to remind myself which arg is the search term and which is the text to search. Call them <code>searchTerm</code> and <code>text</code>.</li> <li>Production code doesn't use the default package.</li> <li>Production code doesn't use <code>System.out.println()</code>.</li> <li>Your javadoc need improving, it needs to tell the user <em>everything</em> they need to know about the code.</li> <li>I would consider using static methods for a class with no class variables.</li> <li>I would also consider allowing the user to specify their own start and end highlighting markers (I wouldn't use static methods if I did this).</li> <li>I wouldn't <code>trim()</code> unless this was specified as a requirement. If I did, then obviously this behaviour would be documented in the javadoc.</li> </ul> <p>I wouldn't worry about the algorithm used for searching, Knuth-Morris-Pratt looks good but they shouldn't expect you to know about it and implement it unless the job spec specifically asked for experience/expertise in string searching.</p>
 

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