| 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.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 | |
|
| 57 | 0 | throw new UnsupportedOperationException("remove"); |
| 58 | |
} |
| 59 | |
|
| 60 | |
public void reset() { |
| 61 | 49 | index_ = INITIAL_INDEX; |
| 62 | 49 | } |
| 63 | |
|
| 64 | |
} |