001: /*
002: * $RCSfile: CaselessStringKeyHashtable.java,v $
003: *
004: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Use is subject to license terms.
007: *
008: * $Revision: 1.1 $
009: * $Date: 2005/02/11 04:56:59 $
010: * $State: Exp $
011: */
012: package com.sun.media.jai.util;
013:
014: import java.util.Hashtable;
015: import java.util.Map;
016: import javax.media.jai.util.CaselessStringKey;
017:
018: /**
019: * A Hashtable where the keys are <code>CaselessStringKey</code>s.
020: */
021: public class CaselessStringKeyHashtable extends Hashtable implements
022: Cloneable, java.io.Serializable {
023:
024: /**
025: * Constructs a new, empty CaselessStringKeyHashtable.
026: */
027: public CaselessStringKeyHashtable() {
028: super ();
029: }
030:
031: /**
032: * Constructs a new CaselessStringKeyHashtable with the same
033: * mappings as the given Map.
034: *
035: * @param t the map whose mappings are to be placed in this map.
036: */
037: public CaselessStringKeyHashtable(Map t) {
038: super (t);
039: }
040:
041: /**
042: * Returns a clone of the <code>CaselessStringKeyHashtable</code>
043: * as an <code>Object</code>.
044: */
045: public Object clone() {
046: return super .clone();
047: }
048:
049: /**
050: * Tests if the specified <code>String</code> is a key in this
051: * hashtable. The key is wrapped by a <code>CaselessStringKey</code>
052: * before being looked up.
053: *
054: * @param key possible key.
055: *
056: * @return <code>true</code> if and only if the specified object
057: * is a key in this hashtable, as determined by the
058: * <tt>equals</tt> method; <code>false</code> otherwise.
059: */
060: public boolean containsKey(String key) {
061: return super .containsKey(new CaselessStringKey(key));
062: }
063:
064: /**
065: * Tests if the specified <code>CaselessStringKey</code> is a key in
066: * this hashtable.
067: *
068: * @param key possible key.
069: *
070: * @return <code>true</code> if and only if the specified object
071: * is a key in this hashtable, as determined by the
072: * <tt>equals</tt> method; <code>false</code> otherwise.
073: */
074: public boolean containsKey(CaselessStringKey key) {
075: return super .containsKey(key);
076: }
077:
078: /**
079: * Allow only <code>String</code> and <code>CaselessStringKey</code>
080: * keys to be looked up. This always throws an IllegalArgumentException.
081: *
082: * @param key possible key.
083: *
084: * @return always throws IllegalArgumentException.
085: */
086: public boolean containsKey(Object key) {
087: throw new IllegalArgumentException();
088: }
089:
090: /**
091: * Returns the value to which the specified key is mapped in this
092: * hashtable. The key is wrapped by a <code>CaselessStringKey</code>
093: * before being looked up.
094: *
095: * @param key a key in the hashtable.
096: *
097: * @return the value to which the key is mapped in this hashtable;
098: * <code>null</code> if the key is not mapped to any value in
099: * this hashtable.
100: * @see #put(String, Object)
101: */
102: public Object get(String key) {
103: return super .get(new CaselessStringKey(key));
104: }
105:
106: /**
107: * Returns the value to which the specified key is mapped in this
108: * hashtable.
109: *
110: * @param key a key in the hashtable.
111: *
112: * @return the value to which the key is mapped in this hashtable;
113: * <code>null</code> if the key is not mapped to any value in
114: * this hashtable.
115: * @see #put(CaselessStringKey, Object)
116: */
117: public Object get(CaselessStringKey key) {
118: return super .get(key);
119: }
120:
121: /**
122: * Allow only String and CaselessStringKey keys to be looked up.
123: * This always throws an IllegalArgumentException.
124: *
125: * @param key possible key.
126: *
127: * @return always throws IllegalArgumentException.
128: * @see #put(Object, Object)
129: */
130: public Object get(Object key) {
131: throw new IllegalArgumentException();
132: }
133:
134: /**
135: * Maps the specified <code>key</code> to the specified
136: * <code>value</code> in this hashtable. Neither the key nor
137: * the value can be <code>null</code>. The key is wrapped by a
138: * <code>CaselessStringKey</code> before mapping the key to the
139: * value. <p>
140: *
141: * The value can be retrieved by calling the <code>get</code> method
142: * with a key that is equal to the original key.
143: *
144: * @param key the hashtable key.
145: * @param value the value.
146: * @return the previous value of the specified key in this hashtable,
147: * or <code>null</code> if it did not have one.
148: * @exception IllegalArgumentException if the key or value is
149: * <code>null</code>.
150: * @see Object#equals(Object)
151: * @see #get(String)
152: */
153: public Object put(String key, Object value) {
154: if (key == null || value == null) {
155: throw new IllegalArgumentException(JaiI18N
156: .getString("Generic0"));
157: }
158:
159: return super .put(new CaselessStringKey(key), value);
160: }
161:
162: /**
163: * Maps the specified <code>key</code> to the specified
164: * <code>value</code> in this hashtable. Neither the key nor the
165: * value can be <code>null</code>. <p>
166: *
167: * The value can be retrieved by calling the <code>get</code> method
168: * with a key that is equal to the original key.
169: *
170: * @param key the hashtable key.
171: * @param value the value.
172: * @return the previous value of the specified key in this hashtable,
173: * or <code>null</code> if it did not have one.
174: * @exception IllegalArgumentException if the key or value is
175: * <code>null</code>.
176: * @see Object#equals(Object)
177: * @see #get(CaselessStringKey)
178: */
179: public Object put(CaselessStringKey key, Object value) {
180: if (key == null || value == null) {
181: throw new IllegalArgumentException(JaiI18N
182: .getString("Generic0"));
183: }
184:
185: return super .put(key, value);
186: }
187:
188: /**
189: * Allow only String and CaselessStringKey keys to be mapped.
190: * This always throws an IllegalArgumentException.
191: *
192: * @param key possible key.
193: * @param value the value.
194: *
195: * @return always throws IllegalArgumentException.
196: * @see #get(Object)
197: */
198: public Object put(Object key, Object value) {
199: throw new IllegalArgumentException();
200: }
201:
202: /**
203: * Removes the key (and its corresponding value) from this
204: * hashtable. This method does nothing if the key is not in the
205: * hashtable. The key is wrapped by a <code>CaselessStringKey</code>
206: * before trying to remove the entry.
207: *
208: * @param key the key that needs to be removed.
209: * @return the value to which the key had been mapped in this hashtable,
210: * or <code>null</code> if the key did not have a mapping.
211: */
212: public Object remove(String key) {
213: return super .remove(new CaselessStringKey(key));
214: }
215:
216: /**
217: * Removes the key (and its corresponding value) from this
218: * hashtable. This method does nothing if the key is not in the
219: * hashtable.
220: *
221: * @param key the key that needs to be removed.
222: * @return the value to which the key had been mapped in this hashtable,
223: * or <code>null</code> if the key did not have a mapping.
224: */
225: public Object remove(CaselessStringKey key) {
226: return super .remove(key);
227: }
228:
229: /**
230: * Allow only String and CaselessStringKey keys to be removed.
231: * This always throws an IllegalArgumentException.
232: *
233: * @param key possible key.
234: *
235: * @return always throws IllegalArgumentException.
236: * @see #get(Object)
237: */
238: public Object remove(Object key) {
239: throw new IllegalArgumentException();
240: }
241: }
|