| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.seasar.teeda.core.util; |
| 17 | |
|
| 18 | |
import java.io.IOException; |
| 19 | |
import java.util.Collection; |
| 20 | |
import java.util.Enumeration; |
| 21 | |
import java.util.Iterator; |
| 22 | |
import java.util.Map; |
| 23 | |
|
| 24 | |
import org.apache.commons.collections.iterators.IteratorChain; |
| 25 | |
import org.seasar.framework.exception.IORuntimeException; |
| 26 | |
import org.seasar.framework.util.EmptyIterator; |
| 27 | |
import org.seasar.framework.util.EnumerationIterator; |
| 28 | |
|
| 29 | |
public class IteratorUtil { |
| 30 | |
|
| 31 | 1 | private static final EmptyIterator EMPTY_ITERATOR = new EmptyIterator(); |
| 32 | |
|
| 33 | 0 | private IteratorUtil() { |
| 34 | 0 | } |
| 35 | |
|
| 36 | |
public static Iterator getIterator(Collection collection) { |
| 37 | 135 | if (collection != null && !collection.isEmpty()) { |
| 38 | 104 | return collection.iterator(); |
| 39 | |
} else { |
| 40 | 31 | return EMPTY_ITERATOR; |
| 41 | |
} |
| 42 | |
} |
| 43 | |
|
| 44 | |
public static Iterator getEntryIterator(Map map) { |
| 45 | 30 | if (map != null && !map.isEmpty()) { |
| 46 | 17 | return map.entrySet().iterator(); |
| 47 | |
} else { |
| 48 | 13 | return EMPTY_ITERATOR; |
| 49 | |
} |
| 50 | |
} |
| 51 | |
|
| 52 | |
public static Iterator getCompositeIterator(Map map1, Map map2) { |
| 53 | 0 | IteratorChain chain = new IteratorChain(); |
| 54 | 0 | chain.addIterator(map1.keySet().iterator()); |
| 55 | 0 | chain.addIterator(map2.keySet().iterator()); |
| 56 | 0 | return chain; |
| 57 | |
} |
| 58 | |
|
| 59 | |
public static Iterator getResourcesIterator(ClassLoader loader, String path) { |
| 60 | |
try { |
| 61 | 1 | Enumeration e = loader.getResources(path); |
| 62 | 1 | return new EnumerationIterator(e); |
| 63 | 0 | } catch (IOException e) { |
| 64 | 0 | throw new IORuntimeException(e); |
| 65 | |
} |
| 66 | |
} |
| 67 | |
|
| 68 | |
} |