KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > codenorm > IntStringHashtable


1 package net.sf.saxon.codenorm;
2
3 import java.util.HashMap JavaDoc;
4
5 /**
6  * Integer-String hash table. Uses Java Hashtable for now.
7  * @author Mark Davis
8  * @author Michael Kay - modified to use a HashMap and to specify an initial size
9  */

10
11 public class IntStringHashtable {
12     static final String JavaDoc copyright = "Copyright © 1998-1999 Unicode, Inc.";
13
14     public IntStringHashtable (String JavaDoc defaultValue, int initialSize) {
15         this.defaultValue = defaultValue;
16         table = new HashMap JavaDoc(initialSize);
17     }
18
19     public void put(int key, String JavaDoc value) {
20         if (value == defaultValue) {
21             table.remove(new Integer JavaDoc(key));
22         } else {
23             table.put(new Integer JavaDoc(key), value);
24         }
25     }
26
27     public String JavaDoc get(int key) {
28         Object JavaDoc value = table.get(new Integer JavaDoc(key));
29         if (value == null) return defaultValue;
30         return (String JavaDoc)value;
31     }
32
33     private String JavaDoc defaultValue;
34     private HashMap JavaDoc table;
35 }
Popular Tags