@Test public void testGeneralMetacharEscaping() { assertTrue(new LikeCondition("a%(b").match("aaa(b")); assertTrue(new LikeCondition("a%)b").match("aaa)b")); assertTrue(new LikeCondition("a%[b").match("aaa[b")); assertTrue(new LikeCondition("a%]b").match("aaa]b")); assertTrue(new LikeCondition("a%{b").match("aaa{b")); assertTrue(new LikeCondition("a%}b").match("aaa}b")); assertTrue(new LikeCondition("a%$b").match("aaa$b")); assertTrue(new LikeCondition("a%^b").match("aaa^b")); assertTrue(new LikeCondition("a%.b").match("aaa.b")); assertTrue(new LikeCondition("a%|b").match("aaa|b")); assertTrue(new LikeCondition("a%\\b").match("aaa\\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();  }