001
014
015 package com.liferay.portal.language;
016
017 import java.util.Enumeration;
018 import java.util.Iterator;
019 import java.util.NoSuchElementException;
020 import java.util.Set;
021
022
025 public class ResourceBundleEnumeration implements Enumeration<String> {
026
027 public ResourceBundleEnumeration(
028 Set<String> set, Enumeration<String> enumeration) {
029
030 _set = set;
031 _enumeration = enumeration;
032
033 _iterator = set.iterator();
034 }
035
036 @Override
037 public boolean hasMoreElements() {
038 if (_nextElement == null) {
039 if (_iterator.hasNext()) {
040 _nextElement = _iterator.next();
041 }
042 else if (_enumeration != null) {
043 while ((_nextElement == null) &&
044 _enumeration.hasMoreElements()) {
045
046 _nextElement = _enumeration.nextElement();
047
048 if (_set.contains(_nextElement)) {
049 _nextElement = null;
050 }
051 }
052 }
053 }
054
055 return _nextElement != null;
056 }
057
058 @Override
059 public String nextElement() {
060 if (hasMoreElements()) {
061 String nextElement = _nextElement;
062
063 _nextElement = null;
064
065 return nextElement;
066 }
067
068 throw new NoSuchElementException();
069 }
070
071 private final Enumeration<String> _enumeration;
072 private final Iterator<String> _iterator;
073 private String _nextElement;
074 private final Set<String> _set;
075
076 }