KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > util > IdentityHashtableEnumerator


1 /*
2  * @(#)IdentityHashtableEnumerator.java 1.2 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 /*
9  * Licensed Materials - Property of IBM
10  * RMI-IIOP v1.0
11  * Copyright IBM Corp. 1998 1999 All Rights Reserved
12  *
13  * US Government Users Restricted Rights - Use, duplication or
14  * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
15  */

16
17 package com.sun.corba.se.impl.util;
18
19 import java.util.Dictionary JavaDoc;
20 import java.util.Enumeration JavaDoc;
21 import java.util.NoSuchElementException JavaDoc;
22
23 /**
24  * A hashtable enumerator class. This class should remain opaque
25  * to the client. It will use the Enumeration interface.
26  */

27 class IdentityHashtableEnumerator implements Enumeration JavaDoc {
28     boolean keys;
29     int index;
30     IdentityHashtableEntry table[];
31     IdentityHashtableEntry entry;
32
33     IdentityHashtableEnumerator(IdentityHashtableEntry table[], boolean keys) {
34     this.table = table;
35     this.keys = keys;
36     this.index = table.length;
37     }
38     
39     public boolean hasMoreElements() {
40     if (entry != null) {
41         return true;
42     }
43     while (index-- > 0) {
44         if ((entry = table[index]) != null) {
45         return true;
46         }
47     }
48     return false;
49 }
50
51 public Object JavaDoc nextElement() {
52     if (entry == null) {
53     while ((index-- > 0) && ((entry = table[index]) == null));
54     }
55     if (entry != null) {
56         IdentityHashtableEntry e = entry;
57     entry = e.next;
58     return keys ? e.key : e.value;
59     }
60     throw new NoSuchElementException JavaDoc("IdentityHashtableEnumerator");
61     }
62 }
63
Popular Tags