### Question:
LikeComparatorFactory implements Function<byte[], ByteArrayComparable> { static String likeToRegex(String like) { StringBuilder builder = new StringBuilder(); boolean wasPercent = false; for (int i = 0; i < like.length(); ++i) { char c = like.charAt(i); if (isPlain(c)) { if (wasPercent) { wasPercent = false; builder.append(".*"); } builder.append(c); } else if (wasPercent) { wasPercent = false; if (c == '%') { builder.append('%'); } else { builder.append(".*").append(c); } } else { if (c == '%') { wasPercent = true; } else { builder.append('\\').append(c); } } } if (wasPercent) { builder.append(".*"); } return builder.toString(); }  ByteArrayComparable apply(byte[] bytes); static final LikeComparatorFactory INSTANCE; }### Answer:
@Test public void likeToRegexConversion() { assertEquals("as is", likeToRegex("as is")); assertEquals("last percent .*", likeToRegex("last percent %")); assertEquals("middle.*percent", likeToRegex("middle%percent")); assertEquals(".*first percent", likeToRegex("%first percent")); assertEquals("%", likeToRegex("%%")); assertEquals("%.*", likeToRegex("%%%")); assertEquals("\\" + "{" + "\\" + "[", likeToRegex("{[")); }