
com.marklogic.client.datamovement.PeekingIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of marklogic-client-api Show documentation
Show all versions of marklogic-client-api Show documentation
The official MarkLogic Java client API.
The newest version!
/*
* Copyright © 2024 MarkLogic Corporation. All Rights Reserved.
*/
package com.marklogic.client.datamovement;
import java.util.Iterator;
import com.marklogic.client.MarkLogicInternalException;
public class PeekingIterator implements Iterator {
private Iterator wrappedItr;
private T first;
private boolean isFirst = true;
public PeekingIterator(Iterator itr) {
if(itr == null)
throw new MarkLogicInternalException("Iterator cannot be null");
this.wrappedItr = itr;
if (wrappedItr.hasNext()) {
first = wrappedItr.next();
} else {
isFirst = false;
}
}
@Override
public T next() {
if (isFirst) {
isFirst = false;
return first;
}
return wrappedItr.next();
}
@Override
public boolean hasNext() {
return wrappedItr.hasNext();
}
public T getFirst() {
return first;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy