Coverage Report - org.seasar.teeda.core.util.LoopIterator
 
Classes in this File Line Coverage Branch Coverage Complexity
LoopIterator
94%
17/18
100%
6/6
2.2
 
 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.util.Iterator;
 19  
 import java.util.NoSuchElementException;
 20  
 
 21  
 import org.seasar.framework.util.AssertionUtil;
 22  
 
 23  
 public class LoopIterator implements Iterator {
 24  
 
 25  
     private static final int INITIAL_INDEX = 0;
 26  
 
 27  
     private Object[] values_;
 28  
 
 29  29
     private int index_ = INITIAL_INDEX;
 30  
 
 31  29
     public LoopIterator(Object[] values) {
 32  29
         AssertionUtil.assertNotNull("values is null.", values);
 33  28
         values_ = values;
 34  28
     }
 35  
 
 36  
     public boolean hasNext() {
 37  112
         if (values_.length > 0) {
 38  83
             return true;
 39  
         }
 40  29
         return false;
 41  
     }
 42  
 
 43  
     public Object next() {
 44  82
         if (values_.length < 1) {
 45  1
             throw new NoSuchElementException("next");
 46  
         }
 47  81
         if (values_.length <= index_) {
 48  22
             reset();
 49  
         }
 50  81
         Object value = values_[index_];
 51  81
         index_++;
 52  81
         return value;
 53  
     }
 54  
 
 55  
     public void remove() {
 56  
         // XXX should be supported?
 57  0
         throw new UnsupportedOperationException("remove");
 58  
     }
 59  
 
 60  
     public void reset() {
 61  49
         index_ = INITIAL_INDEX;
 62  49
     }
 63  
 
 64  
 }