Coverage Report - org.seasar.teeda.core.util.IteratorUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
IteratorUtil
53%
9/17
100%
8/8
2.4
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 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  
 }