1. /*
  2. * @(#)ResourceBundleEnumeration.java 1.3 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.util;
  8. /**
  9. * Implements an Enumeration that combines elements from a Set and
  10. * an Enumeration. Used by ListResourceBundle and PropertyResourceBundle.
  11. */
  12. class ResourceBundleEnumeration implements Enumeration {
  13. Set set;
  14. Iterator iterator;
  15. Enumeration enumeration; // may remain null
  16. /**
  17. * Constructs a resource bundle enumeration.
  18. * @param set an set providing some elements of the enumeration
  19. * @param enumeration an enumeration providing more elements of the enumeration.
  20. * enumeration may be null.
  21. */
  22. ResourceBundleEnumeration(Set set, Enumeration enumeration) {
  23. this.set = set;
  24. this.iterator = set.iterator();
  25. this.enumeration = enumeration;
  26. }
  27. Object next = null;
  28. public boolean hasMoreElements() {
  29. if (next == null) {
  30. if (iterator.hasNext()) {
  31. next = iterator.next();
  32. } else if (enumeration != null) {
  33. while (next == null && enumeration.hasMoreElements()) {
  34. next = enumeration.nextElement();
  35. if (set.contains(next)) {
  36. next = null;
  37. }
  38. }
  39. }
  40. }
  41. return next != null;
  42. }
  43. public Object nextElement() {
  44. if (hasMoreElements()) {
  45. Object result = next;
  46. next = null;
  47. return result;
  48. } else {
  49. throw new NoSuchElementException();
  50. }
  51. }
  52. }