1
//$Id: MatchMode.java 5685 2005-02-12 07:19:50Z steveebersole $
2
package org.hibernate.criterion;
4
import java.io.Serializable;
5
import java.util.HashMap;
9
* Represents an strategy for matching strings using "like".
11
* @see Example#enableLike(MatchMode)
14
public abstract class MatchMode implements Serializable {
15
private final String name;
16
private static final Map INSTANCES = new HashMap();
18
protected MatchMode(String name) {
21
public String toString() {
26
* Match the entire string to the pattern
28
public static final MatchMode EXACT = new MatchMode("EXACT") {
29
public String toMatchString(String pattern) {
35
* Match the start of the string to the pattern
37
public static final MatchMode START = new MatchMode("START") {
38
public String toMatchString(String pattern) {
44
* Match the end of the string to the pattern
46
public static final MatchMode END = new MatchMode("END") {
47
public String toMatchString(String pattern) {
53
* Match the pattern anywhere in the string
55
public static final MatchMode ANYWHERE = new MatchMode("ANYWHERE") {
56
public String toMatchString(String pattern) {
57
return '%' + pattern + '%';
62
INSTANCES.put( EXACT.name, EXACT );
63
INSTANCES.put( END.name, END );
64
INSTANCES.put( START.name, START );
65
INSTANCES.put( ANYWHERE.name, ANYWHERE );
68
private Object readResolve() {
69
return INSTANCES.get(name);
73
* convert the pattern, by appending/prepending "%"
75
public abstract String toMatchString(String pattern);