<commit_before>package ru.spbau.mit.dbmsau.table;

import ru.spbau.mit.dbmsau.pages.Page;
import ru.spbau.mit.dbmsau.pages.PagesList;
import ru.spbau.mit.dbmsau.pages.Record;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;

public class RecordSet implements Iterable<TableRecord>, Iterator<TableRecord> {
    private Table table;
    private PagesList fullPages, notFullPages;

    private Queue<PagesList> pagesLists = new LinkedList<>();
    private PagesList currentList;
    private Iterator<Record> currentPageIterator = null;

    public RecordSet(Table table, PagesList fullPages, PagesList notFullPages) {
        this.table = table;
        this.fullPages = fullPages;
        this.notFullPages = notFullPages;
    }

    @Override
    public Iterator<TableRecord> iterator() {
        pagesLists.clear();

        pagesLists.add(fullPages);
        pagesLists.add(notFullPages);

        currentList = pagesLists.poll();
        currentPageIterator = null;
        return this;
    }

    private void moveUntilNext() {
        while (currentPageIterator == null || !currentPageIterator.hasNext()) {
            Page next = currentList.popPage();

            if (next == null) {
                if (pagesLists.size() == 0) {
                    return;
                } else {
                    currentList = pagesLists.poll();
                    continue;
                }
            }

            currentPageIterator = new TableRecordsPage(table, next).iterator();
        }
    }

    @Override
    public boolean hasNext() {
        moveUntilNext();

        return currentPageIterator != null && currentPageIterator.hasNext();
    }

    @Override
    public TableRecord next() {
        moveUntilNext();

        return new TableRecord(currentPageIterator.next(), table);
    }

    @Override
    public void remove() {<commit_msg>Second Select Problem fixed<commit_after>package ru.spbau.mit.dbmsau.table;

import ru.spbau.mit.dbmsau.pages.Page;
import ru.spbau.mit.dbmsau.pages.PagesList;
import ru.spbau.mit.dbmsau.pages.Record;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;

public class RecordSet implements Iterable<TableRecord>, Iterator<TableRecord> {
    private Table table;
    private PagesList fullPages, notFullPages;

    private Queue<PagesList> pagesLists = new LinkedList<>();
    private Iterator<Page> currentListIterator;
    private Iterator<Record> currentPageIterator = null;

    public RecordSet(Table table, PagesList fullPages, PagesList notFullPages) {
        this.table = table;
        this.fullPages = fullPages;
        this.notFullPages = notFullPages;
    }

    @Override
    public Iterator<TableRecord> iterator() {
        pagesLists.clear();

        pagesLists.add(fullPages);
        pagesLists.add(notFullPages);

        currentListIterator = pagesLists.poll().iterator();
        currentPageIterator = null;
        return this;
    }

    private void moveUntilNext() {
        while (currentPageIterator == null || !currentPageIterator.hasNext()) {
            if (!currentListIterator.hasNext()) {
                if (pagesLists.size() == 0) {
                    return;
                } else {
                    currentListIterator = pagesLists.poll().iterator();
                    continue;
                }
            } else {
                 currentPageIterator = new TableRecordsPage(table, currentListIterator.next()).iterator();
            }
        }
    }

    @Override
    public boolean hasNext() {
        moveUntilNext();

        return currentPageIterator != null && currentPageIterator.hasNext();
    }

    @Override
    public TableRecord next() {
        moveUntilNext();

        return new TableRecord(currentPageIterator.next(), table);
    }

    @Override
    public void remove() {
{'fraction_non_alphanumeric': 0.09953343701399689, 'fraction_numerical': 0.0005184033177812338, 'mean_word_length': 2.4363312555654497, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3517902', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1018, 'n_words': 224}