KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.saxon.codenorm;
2
3 import java.util.HashMap JavaDoc;
4
5 /**
6  * Integer hash table. Uses Java Hashtable in stub version
7  * Copyright (c) 1991-2005 Unicode, Inc.
8  * For terms of use, see http://www.unicode.org/terms_of_use.html
9  * For documentation, see UAX#15.<br>
10  * @author Mark Davis
11  * @author Michael Kay - modified to use a HashMap and specify an initial size
12  */

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