01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.user.rebind;
17:
18: import java.util.Map;
19:
20: /**
21: * Common base class for Enum-like 1.4 classes, often needed for generator-like
22: * functionality.
23: */
24: class Enum {
25: /**
26: * Requires the specified object from the pool.
27: *
28: * @param key the key associated with the <code>Enum</code>
29: * @param pool pool to draw key from
30: * @return associated <code>Enum</code>
31: */
32: public static Enum require(String key, Map<String, Enum> pool) {
33: Enum t = pool.get(key);
34: if (t == null) {
35: throw new IllegalArgumentException(key
36: + " is not a valid Enum type. Current options are "
37: + pool.keySet());
38: }
39: return t;
40: }
41:
42: /**
43: * Associated key.
44: */
45: final String key;
46:
47: /**
48: * Creates a new <code>Enum</code> in a given pool.
49: *
50: * @param key associated key
51: * @param pool associated pool
52: */
53: protected Enum(String key, Map<String, Enum> pool) {
54: this .key = key;
55: pool.put(key, this );
56: }
57:
58: /**
59: * @see java.lang.Object#toString()
60: */
61: @Override
62: public String toString() {
63: return key;
64: }
65: }
|