01: package org.apache.lucene.search.regex;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19:
20: import java.util.regex.Pattern;
21:
22: /**
23: * An implementation tying Java's built-in java.util.regex to RegexQuery.
24: *
25: * Note that because this implementation currently only returns null from
26: * {@link #prefix} that queries using this implementation will enumerate and
27: * attempt to {@link #match} each term for the specified field in the index.
28: */
29: public class JavaUtilRegexCapabilities implements RegexCapabilities {
30: private Pattern pattern;
31:
32: public void compile(String pattern) {
33: this .pattern = Pattern.compile(pattern);
34: }
35:
36: public boolean match(String string) {
37: return pattern.matcher(string).lookingAt();
38: }
39:
40: public String prefix() {
41: return null;
42: }
43:
44: public boolean equals(Object o) {
45: if (this == o)
46: return true;
47: if (o == null || getClass() != o.getClass())
48: return false;
49:
50: final JavaUtilRegexCapabilities that = (JavaUtilRegexCapabilities) o;
51:
52: if (pattern != null ? !pattern.equals(that.pattern)
53: : that.pattern != null)
54: return false;
55:
56: return true;
57: }
58:
59: public int hashCode() {
60: return (pattern != null ? pattern.hashCode() : 0);
61: }
62: }
|