1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.mimo.netty.handler.codec.icap;
15
16 import java.util.HashMap;
17 import java.util.Map;
18
19
20
21
22
23
24
25 public final class IcapMethod {
26
27
28
29
30 public static final IcapMethod REQMOD = new IcapMethod("REQMOD");
31
32
33
34
35 public static final IcapMethod RESPMOD = new IcapMethod("RESPMOD");
36
37
38
39
40 public static final IcapMethod OPTIONS = new IcapMethod("OPTIONS");
41
42 private static final Map<String, IcapMethod> METHOD_MAP =
43 new HashMap<String, IcapMethod>();
44
45 static {
46 METHOD_MAP.put(REQMOD.toString(),REQMOD);
47 METHOD_MAP.put(RESPMOD.toString(),RESPMOD);
48 METHOD_MAP.put(OPTIONS.toString(),OPTIONS);
49 }
50
51 private String name;
52
53 IcapMethod(String name) {
54 this.name = name;
55 }
56
57
58
59
60
61
62 public static IcapMethod valueOf(String name) {
63 if (name == null) {
64 throw new NullPointerException("name");
65 }
66
67 name = name.trim().toUpperCase();
68 if (name.length() == 0) {
69 throw new IllegalArgumentException("empty name");
70 }
71
72 IcapMethod result = METHOD_MAP.get(name);
73 if (result != null) {
74 return result;
75 } else {
76 return new IcapMethod(name);
77 }
78 }
79
80 @Override
81 public String toString() {
82 return name;
83 }
84 }