1 package org.hibernate.criterion; 3 4 import java.io.Serializable ; 5 import java.util.HashMap ; 6 import java.util.Map ; 7 8 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 28 public static final MatchMode EXACT = new MatchMode("EXACT") { 29 public String toMatchString(String pattern) { 30 return pattern; 31 } 32 }; 33 34 37 public static final MatchMode START = new MatchMode("START") { 38 public String toMatchString(String pattern) { 39 return pattern + '%'; 40 } 41 }; 42 43 46 public static final MatchMode END = new MatchMode("END") { 47 public String toMatchString(String pattern) { 48 return '%' + pattern; 49 } 50 }; 51 52 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 75 public abstract String toMatchString(String pattern); 76 77 } 78 79 80 81 82 83 | Popular Tags |