1. /*
  2. * @(#)ResourceBundleEnumeration.java 1.5 04/05/05
  3. *
  4. * Copyright 2004 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<String> {
  13. Set<String> set;
  14. Iterator<String> iterator;
  15. Enumeration<String> 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<String> set, Enumeration<String> enumeration) {
  23. this.set = set;
  24. this.iterator = set.iterator();
  25. this.enumeration = enumeration;
  26. }
  27. String 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 String nextElement() {
  44. if (hasMoreElements()) {
  45. String result = next;
  46. next = null;
  47. return result;
  48. } else {
  49. throw new NoSuchElementException();
  50. }
  51. }
  52. }