@Test public void testEscapeChar() { assertTrue(new LikeCondition("a\\%b").match("a%b")); assertFalse(new LikeCondition("a\\%b").match("aXb")); assertFalse(new LikeCondition("a\\%b").match("ab")); assertTrue(new LikeCondition("a\\\\b").match("a\\b")); assertTrue(new LikeCondition("a~%b", '~').match("a%b")); assertFalse(new LikeCondition("a~%b", '~').match("aXb")); assertFalse(new LikeCondition("a~%b", '~').match("ab")); assertTrue(new LikeCondition("a~~b", '~').match("a~b")); }
@Override public boolean match(String attributeValue) { if (attributeValue == null) { return false; } switch (type) { case Equals: return attributeValue.equals(value); case StartsWith: return (length == -1 || length == attributeValue.length()) && attributeValue.startsWith(value); case EndsWith: return (length == -1 || length == attributeValue.length()) && attributeValue.endsWith(value); case Contains: return attributeValue.contains(value); case Regexp: return regexPattern.matcher(attributeValue).matches(); default: throw new IllegalStateException("Unexpected type " + type); } }
LikeCondition implements Condition<String> { @Override public boolean match(String attributeValue) { if (attributeValue == null) { return false; } switch (type) { case Equals: return attributeValue.equals(value); case StartsWith: return (length == -1 || length == attributeValue.length()) && attributeValue.startsWith(value); case EndsWith: return (length == -1 || length == attributeValue.length()) && attributeValue.endsWith(value); case Contains: return attributeValue.contains(value); case Regexp: return regexPattern.matcher(attributeValue).matches(); default: throw new IllegalStateException("Unexpected type " + type); } } }
LikeCondition implements Condition<String> { @Override public boolean match(String attributeValue) { if (attributeValue == null) { return false; } switch (type) { case Equals: return attributeValue.equals(value); case StartsWith: return (length == -1 || length == attributeValue.length()) && attributeValue.startsWith(value); case EndsWith: return (length == -1 || length == attributeValue.length()) && attributeValue.endsWith(value); case Contains: return attributeValue.contains(value); case Regexp: return regexPattern.matcher(attributeValue).matches(); default: throw new IllegalStateException("Unexpected type " + type); } } LikeCondition(String likePattern);  LikeCondition(String likePattern, char escapeCharacter); }
LikeCondition implements Condition<String> { @Override public boolean match(String attributeValue) { if (attributeValue == null) { return false; } switch (type) { case Equals: return attributeValue.equals(value); case StartsWith: return (length == -1 || length == attributeValue.length()) && attributeValue.startsWith(value); case EndsWith: return (length == -1 || length == attributeValue.length()) && attributeValue.endsWith(value); case Contains: return attributeValue.contains(value); case Regexp: return regexPattern.matcher(attributeValue).matches(); default: throw new IllegalStateException("Unexpected type " + type); } } LikeCondition(String likePattern);  LikeCondition(String likePattern, char escapeCharacter); @Override boolean match(String attributeValue); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
LikeCondition implements Condition<String> { @Override public boolean match(String attributeValue) { if (attributeValue == null) { return false; } switch (type) { case Equals: return attributeValue.equals(value); case StartsWith: return (length == -1 || length == attributeValue.length()) && attributeValue.startsWith(value); case EndsWith: return (length == -1 || length == attributeValue.length()) && attributeValue.endsWith(value); case Contains: return attributeValue.contains(value); case Regexp: return regexPattern.matcher(attributeValue).matches(); default: throw new IllegalStateException("Unexpected type " + type); } } LikeCondition(String likePattern);  LikeCondition(String likePattern, char escapeCharacter); @Override boolean match(String attributeValue); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString();  }