ru.vyarus.yaml.updater.parse.comments.util.CountingIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yaml-config-updater Show documentation
Show all versions of yaml-config-updater Show documentation
Merges current yaml config with a new version to add missed properties
The newest version!
package ru.vyarus.yaml.updater.parse.comments.util;
import java.util.Iterator;
/**
* Iterator, remembering processed items count.
*
* @param value type
* @author Vyacheslav Rusakov
* @since 23.04.2021
*/
public class CountingIterator implements Iterator {
private final Iterator it;
private int pos;
public CountingIterator(final Iterator it) {
this.it = it;
}
@Override
public boolean hasNext() {
return it.hasNext();
}
@Override
public T next() {
final T res = it.next();
// increment after to not count invalid attempts at the end
pos++;
return res;
}
/**
* @return current item position, starting from 0
*/
public int getPosition() {
return pos;
}
}