01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/authz/tags/sakai_2-4-1/authz-impl/impl/src/java/org/sakaiproject/authz/impl/SeriesIterator.java $
03: * $Id: SeriesIterator.java 7163 2006-03-28 20:44:51Z ggolden@umich.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.authz.impl;
21:
22: import java.util.Iterator;
23: import java.util.NoSuchElementException;
24:
25: /**
26: * <p>
27: * SeriesIterator is an iterator over a series of other iterators.
28: * </p>
29: */
30: public class SeriesIterator implements Iterator {
31: /** The enumeration over which this iterates. */
32: protected Iterator[] m_iterators = null;
33:
34: /** The m_iterators index that is current. */
35: protected int m_index = 0;
36:
37: /**
38: * Construct to handle a series of two iterators.
39: *
40: * @param one
41: * The first iterator.
42: * @param two
43: * The second iterator.
44: */
45: public SeriesIterator(Iterator one, Iterator two) {
46: m_iterators = new Iterator[2];
47: m_iterators[0] = one;
48: m_iterators[1] = two;
49:
50: } // SeriesIterator
51:
52: public Object next() throws NoSuchElementException {
53: while (!m_iterators[m_index].hasNext()) {
54: m_index++;
55: if (m_index >= m_iterators.length)
56: throw new NoSuchElementException();
57: }
58: return m_iterators[m_index].next();
59: }
60:
61: public boolean hasNext() {
62: while (!m_iterators[m_index].hasNext()) {
63: m_index++;
64: if (m_index >= m_iterators.length)
65: return false;
66: }
67: return true;
68: }
69:
70: public void remove() {
71: throw new UnsupportedOperationException();
72: }
73: }
|