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. * Licensed Materials - Property of IBM
  9. * RMI-IIOP v1.0
  10. * Copyright IBM Corp. 1998 1999 All Rights Reserved
  11. *
  12. * US Government Users Restricted Rights - Use, duplication or
  13. * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  14. */
  15. package com.sun.corba.se.impl.util;
  16. import java.util.Dictionary;
  17. import java.util.Enumeration;
  18. import java.util.NoSuchElementException;
  19. /**
  20. * A hashtable enumerator class. This class should remain opaque
  21. * to the client. It will use the Enumeration interface.
  22. */
  23. class IdentityHashtableEnumerator implements Enumeration {
  24. boolean keys;
  25. int index;
  26. IdentityHashtableEntry table[];
  27. IdentityHashtableEntry entry;
  28. IdentityHashtableEnumerator(IdentityHashtableEntry table[], boolean keys) {
  29. this.table = table;
  30. this.keys = keys;
  31. this.index = table.length;
  32. }
  33. public boolean hasMoreElements() {
  34. if (entry != null) {
  35. return true;
  36. }
  37. while (index-- > 0) {
  38. if ((entry = table[index]) != null) {
  39. return true;
  40. }
  41. }
  42. return false;
  43. }
  44. public Object nextElement() {
  45. if (entry == null) {
  46. while ((index-- > 0) && ((entry = table[index]) == null));
  47. }
  48. if (entry != null) {
  49. IdentityHashtableEntry e = entry;
  50. entry = e.next;
  51. return keys ? e.key : e.value;
  52. }
  53. throw new NoSuchElementException("IdentityHashtableEnumerator");
  54. }
  55. }