@Override
public List<ChangeContainer> next() {
List<ChangeContainer> changeList;
Entity peekEntity;
long currentId;
EntityType currentEntityType;
// Get the next change from the underlying stream.
peekEntity = sourceIterator.peekNext().getEntityContainer().getEntity();
currentId = peekEntity.getId();
currentEntityType = peekEntity.getType();
// Loop until all history values for the current element are exhausted.
changeList = new ArrayList<ChangeContainer>();
while (sourceIterator.hasNext()) {
ChangeContainer tmpChangeContainer = sourceIterator.peekNext();
// Break out of the loop when we reach the next entity in the stream.
if (currentId != tmpChangeContainer.getEntityContainer().getEntity().getId()
|| !currentEntityType.equals(tmpChangeContainer.getEntityContainer().getEntity().getType())) {
break;
}
// We want the value that we have already peeked from the iterator, so remove it from the iterator.
sourceIterator.next();