Files
ebean/src/main/java/io/ebean/common/ModifyIterator.java
T
Roland PramlandRob Bygrave 40f5596837 add missing @override (#975)
* no effective code change: add missing @override in "io.ebean.*" package
* no effective code change: add missing @override in "io.ebeaninternal.api.*" package
* no effective code change: add missing @override in "io.ebeaninternal.server.*" package
* no effective code change: add missing @override in "io.ebeaninternal.util.*" package
* no effective code change: add missing @override in "io.ebeanservice.*" package
* no effective code change: add missing @override in "src/test/java/"
2017-02-24 00:01:25 +13:00

52 lines
987 B
Java

package io.ebean.common;
import io.ebean.bean.BeanCollection;
import java.util.Iterator;
/**
* Wraps an iterator for the purposes of notifying removals and additions to the
* BeanCollection owner.
* <p>
* This is required for persisting ManyToMany objects. Additions and removals
* become inserts and deletes to the intersection table.
* </p>
*/
class ModifyIterator<E> implements Iterator<E> {
private final BeanCollection<E> owner;
private final Iterator<E> it;
private E last;
/**
* Create with an Owner and the underlying Iterator this wraps.
* <p>
* The owner is notified of the removals.
* </p>
*/
ModifyIterator(BeanCollection<E> owner, Iterator<E> it) {
this.owner = owner;
this.it = it;
}
@Override
public boolean hasNext() {
return it.hasNext();
}
@Override
public E next() {
last = it.next();
return last;
}
@Override
public void remove() {
owner.modifyRemoval(last);
it.remove();
}
}