~ubuntu-branches/ubuntu/wily/libhibernate3-java/wily-proposed

« back to all changes in this revision

Viewing changes to src/org/hibernate/criterion/MatchMode.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-10-14 14:43:34 UTC
  • Revision ID: james.westby@ubuntu.com-20071014144334-eamc8i0q10gs1aro
Tags: upstream-3.2.5
ImportĀ upstreamĀ versionĀ 3.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//$Id: MatchMode.java 5685 2005-02-12 07:19:50Z steveebersole $
 
2
package org.hibernate.criterion;
 
3
 
 
4
import java.io.Serializable;
 
5
import java.util.HashMap;
 
6
import java.util.Map;
 
7
 
 
8
/**
 
9
 * Represents an strategy for matching strings using "like".
 
10
 *
 
11
 * @see Example#enableLike(MatchMode)
 
12
 * @author Gavin King
 
13
 */
 
14
public abstract class MatchMode implements Serializable {
 
15
        private final String name;
 
16
        private static final Map INSTANCES = new HashMap();
 
17
 
 
18
        protected MatchMode(String name) {
 
19
                this.name=name;
 
20
        }
 
21
        public String toString() {
 
22
                return name;
 
23
        }
 
24
 
 
25
        /**
 
26
         * Match the entire string to the pattern
 
27
         */
 
28
        public static final MatchMode EXACT = new MatchMode("EXACT") {
 
29
                public String toMatchString(String pattern) {
 
30
                        return pattern;
 
31
                }
 
32
        };
 
33
 
 
34
        /**
 
35
         * Match the start of the string to the pattern
 
36
         */
 
37
        public static final MatchMode START = new MatchMode("START") {
 
38
                public String toMatchString(String pattern) {
 
39
                        return pattern + '%';
 
40
                }
 
41
        };
 
42
 
 
43
        /**
 
44
         * Match the end of the string to the pattern
 
45
         */
 
46
        public static final MatchMode END = new MatchMode("END") {
 
47
                public String toMatchString(String pattern) {
 
48
                        return '%' + pattern;
 
49
                }
 
50
        };
 
51
 
 
52
        /**
 
53
         * Match the pattern anywhere in the string
 
54
         */
 
55
        public static final MatchMode ANYWHERE = new MatchMode("ANYWHERE") {
 
56
                public String toMatchString(String pattern) {
 
57
                        return '%' + pattern + '%';
 
58
                }
 
59
        };
 
60
 
 
61
        static {
 
62
                INSTANCES.put( EXACT.name, EXACT );
 
63
                INSTANCES.put( END.name, END );
 
64
                INSTANCES.put( START.name, START );
 
65
                INSTANCES.put( ANYWHERE.name, ANYWHERE );
 
66
        }
 
67
 
 
68
        private Object readResolve() {
 
69
                return INSTANCES.get(name);
 
70
        }
 
71
 
 
72
        /**
 
73
         * convert the pattern, by appending/prepending "%"
 
74
         */
 
75
        public abstract String toMatchString(String pattern);
 
76
 
 
77
}
 
78
 
 
79
 
 
80
 
 
81
 
 
82