class CheckedIterator {

    public boolean elementsEqual(@NonNull CheckedIterator<E, T> that) throws T {
        while (this.hasNext()) {
            if (!that.hasNext()) {
                return false;
            }
            Object o1 = this.next();
            Object o2 = that.next();
            if (!Objects.equals(o1, o2)) {
                return false;
            }
        }
        return !that.hasNext();
    }

}