LikeMatch { public boolean match(String left, String right) { if (right == null || left == null) { return false; } if (right.startsWith("\"") && right.endsWith("\"")) { right = right.substring(1, right.length() - 1); } if (right.startsWith("%") && right.endsWith("%")) { return left.contains(right.substring(1, right.length() - 1)); } return (right.startsWith("%") && left.endsWith(right.substring(1))) || (right.endsWith("%") && left.startsWith(right.substring(0, right.length() - 1))) ; }  boolean match(String left, String right);  }
@Test public void testLike() { assertTrue(new LikeMatch().match("MaxBlack", "%Black")); assertTrue(new LikeMatch().match("MaxBlack", "Max%")); assertTrue(new LikeMatch().match("MaxBlack", "%axBl%")); assertFalse(new LikeMatch().match("CarolineChanning", "Max%")); assertFalse(new LikeMatch().match("CarolineChanning", "%Max")); assertTrue(new LikeMatch().match("MaxBlack", "\"%Black\"")); assertFalse(new LikeMatch().match("CarolineChanning", "\"Max%\"")); }