DERBY-3136 improved the LIKE implementation along the lines suggested in this issue, so now WorkHorseForCollatorDatatypes.getCollationElementsForString() is only used for checking that the ESCAPE clause of a LIKE ... ESCAPE ... expression does not contain more than a single collation element (for example to disallow 'ß' in an ESCAPE clause, as it has two collation elements).
Since it's only used for ESCAPE clauses now, and they are typically just a single character, the performance benefits are probably not that big anymore. But we can simplify how the collation elements are calculated now that we only need to check if it's a single element. For example, there is no need to have an intermediate int representation of the collation elements.
Attached is a patch that removes the getCollationElementsForString() and getCountOfCollationElements() methods from WorkHorseForCollatorDatatypes, CollationElementsInterface, and all classes that implement CollationElementsInterface. Those methods are replaced by a simpler hasSingleCollationElement() method.
This shrinks the source files by approximately 100 lines in addition to reducing the number of objects allocated when evaluating LIKE ... ESCAPE with territory based collation, which might (perhaps) slightly improve the performance.
I'm running the full regression test suite on the patch now.