com.ibm.wala.util.collections.ComposedIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.ibm.wala.util Show documentation
Show all versions of com.ibm.wala.util Show documentation
T. J. Watson Libraries for Analysis
The newest version!
/*
* Copyright (c) 2002 - 2006 IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*/
package com.ibm.wala.util.collections;
import java.util.Iterator;
import org.jspecify.annotations.NullUnmarked;
import org.jspecify.annotations.Nullable;
/** A 2-level iterator. has not been tested yet! */
public abstract class ComposedIterator implements Iterator {
private final Iterator outer;
private @Nullable Iterator extends I> inner;
public ComposedIterator(Iterator outer) {
this.outer = outer;
advanceOuter();
}
private void advanceOuter() {
while (outer.hasNext()) {
inner = makeInner(outer.next());
if (inner.hasNext()) {
break;
}
}
if (inner != null && !inner.hasNext()) {
inner = null;
}
}
public abstract Iterator extends I> makeInner(O outer);
@Override
public void remove() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
@Override
public boolean hasNext() {
return (inner != null);
}
@NullUnmarked
@Override
public I next() {
I result = inner.next();
if (!inner.hasNext()) {
advanceOuter();
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy