<commit_before>package ui.issuepanel;

import backend.interfaces.IModel;
import backend.resource.TurboIssue;
import filter.expression.Qualifier;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Priority;
import ui.UI;
import ui.components.IssueListView;
import ui.issuecolumn.ColumnControl;
import ui.issuecolumn.IssueColumn;
import util.KeyPress;
import util.events.IssueSelectedEvent;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Optional;

public class IssuePanel extends IssueColumn {

    private final IModel model;
    private final UI ui;
    private int issueCount;

    private IssueListView listView;
    private final KeyCombination keyCombBoxToList =
        new KeyCodeCombination(KeyCode.DOWN, KeyCombination.CONTROL_DOWN);
    private final KeyCombination keyCombListToBox =
        new KeyCodeCombination(KeyCode.UP, KeyCombination.CONTROL_DOWN);
    private final KeyCombination maximizeWindow =
        new KeyCodeCombination(KeyCode.X, KeyCombination.CONTROL_DOWN);
    private final KeyCombination minimizeWindow =
        new KeyCodeCombination(KeyCode.N, KeyCombination.CONTROL_DOWN);
    private final KeyCombination defaultSizeWindow =
        new KeyCodeCombination(KeyCode.D, KeyCombination.CONTROL_DOWN);

    // IssueCommentCounts and issueNonSelfCommentCounts are accessed whenever the view is updated
    // via listView.setItems in refreshItems. However, an overwrite of the count only happens upon
    // an IssueSelectedEvent.
    private HashMap<Integer, Integer> issueCommentCounts = new HashMap<>();
    private HashMap<Integer, Integer> issueNonSelfCommentCounts = new HashMap<>();

    public IssuePanel(UI ui, IModel model, ColumnControl parentColumnControl, int columnIndex) {
        super(ui, model, parentColumnControl, columnIndex);
        this.model = model;
        this.ui = ui;

        listView = new IssueListView();
        setupListView();
        getChildren().add(listView);

        refreshItems(false);
    }

    /**
     * Determines if an issue has had new comments added (or removed) based on
     * its last-known comment count in {@link #issueCommentCounts}.
     * @param issue
     * @return true if the issue has changed, false otherwise
     */
    private boolean issueHasNewComments(TurboIssue issue, boolean hasMetadata) {
        if (currentFilterExpression.getQualifierNames().contains(Qualifier.UPDATED) && hasMetadata) {
            return issueNonSelfCommentCounts.containsKey(issue.getId()) &&
                    Math.abs(
                            issueNonSelfCommentCounts.get(issue.getId()) - issue.getMetadata().getNonSelfCommentCount()
                    ) > 0;
        } else {
            return issueCommentCounts.containsKey(issue.getId()) &&
                    Math.abs(issueCommentCounts.get(issue.getId()) - issue.getCommentCount()) > 0;
        }
    }

    /**
     * Updates {@link #issueCommentCounts} with the latest counts.
     * Returns a list of issues which have new comments.
     * @return
     */
    private HashSet<Integer> updateIssueCommentCounts(boolean hasMetadata) {
        HashSet<Integer> result = new HashSet<>();
        for (TurboIssue issue : getIssueList()) {
            if (issueCommentCounts.containsKey(issue.getId())) {
                // We know about this issue; check if it's been updated
                if (issueHasNewComments(issue, hasMetadata)) {
                    result.add(issue.getId());
                }
            } else {
                // We don't know about this issue, just put the current comment count.
                issueNonSelfCommentCounts.put(issue.getId(), issue.getMetadata().getNonSelfCommentCount());
                issueCommentCounts.put(issue.getId(), issue.getCommentCount());
            }
        }
        return result;
    }

    @Override
    public void refreshItems(boolean hasMetadata) {
        super.refreshItems(hasMetadata);
        // Only update filter if filter does not contain UPDATED (does not need to wait for metadata)
        // or if hasMetadata is true (metadata has arrived)
        if (!currentFilterExpression.getQualifierNames().contains(Qualifier.UPDATED) || hasMetadata) {
            final HashSet<Integer> issuesWithNewComments = updateIssueCommentCounts(hasMetadata);

            // Set the cell factory every time - this forces the list view to update
            listView.setCellFactory(list ->
                    new IssuePanelCell(model, IssuePanel.this, columnIndex, issuesWithNewComments));
            listView.saveSelection();

            // Supposedly this also causes the list view to update - not sure
            // if it actually does on platforms other than Linux...
            listView.setItems(null);
            listView.setItems(getIssueList());
            issueCount = getIssueList().size();

            listView.restoreSelection();
            this.setId(model.getDefaultRepo() + "_col" + columnIndex);<commit_msg>Added condition to check if updated filter has no items to downloaded metadata for<commit_after>package ui.issuepanel;

import backend.interfaces.IModel;
import backend.resource.TurboIssue;
import filter.expression.Qualifier;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Priority;
import ui.UI;
import ui.components.IssueListView;
import ui.issuecolumn.ColumnControl;
import ui.issuecolumn.IssueColumn;
import util.KeyPress;
import util.events.IssueSelectedEvent;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Optional;

public class IssuePanel extends IssueColumn {

    private final IModel model;
    private final UI ui;
    private int issueCount;

    private IssueListView listView;
    private final KeyCombination keyCombBoxToList =
        new KeyCodeCombination(KeyCode.DOWN, KeyCombination.CONTROL_DOWN);
    private final KeyCombination keyCombListToBox =
        new KeyCodeCombination(KeyCode.UP, KeyCombination.CONTROL_DOWN);
    private final KeyCombination maximizeWindow =
        new KeyCodeCombination(KeyCode.X, KeyCombination.CONTROL_DOWN);
    private final KeyCombination minimizeWindow =
        new KeyCodeCombination(KeyCode.N, KeyCombination.CONTROL_DOWN);
    private final KeyCombination defaultSizeWindow =
        new KeyCodeCombination(KeyCode.D, KeyCombination.CONTROL_DOWN);

    // IssueCommentCounts and issueNonSelfCommentCounts are accessed whenever the view is updated
    // via listView.setItems in refreshItems. However, an overwrite of the count only happens upon
    // an IssueSelectedEvent.
    private HashMap<Integer, Integer> issueCommentCounts = new HashMap<>();
    private HashMap<Integer, Integer> issueNonSelfCommentCounts = new HashMap<>();

    public IssuePanel(UI ui, IModel model, ColumnControl parentColumnControl, int columnIndex) {
        super(ui, model, parentColumnControl, columnIndex);
        this.model = model;
        this.ui = ui;

        listView = new IssueListView();
        setupListView();
        getChildren().add(listView);

        refreshItems(false);
    }

    /**
     * Determines if an issue has had new comments added (or removed) based on
     * its last-known comment count in {@link #issueCommentCounts}.
     * @param issue
     * @return true if the issue has changed, false otherwise
     */
    private boolean issueHasNewComments(TurboIssue issue, boolean hasMetadata) {
        if (currentFilterExpression.getQualifierNames().contains(Qualifier.UPDATED) && hasMetadata) {
            return issueNonSelfCommentCounts.containsKey(issue.getId()) &&
                    Math.abs(
                            issueNonSelfCommentCounts.get(issue.getId()) - issue.getMetadata().getNonSelfCommentCount()
                    ) > 0;
        } else {
            return issueCommentCounts.containsKey(issue.getId()) &&
                    Math.abs(issueCommentCounts.get(issue.getId()) - issue.getCommentCount()) > 0;
        }
    }

    /**
     * Updates {@link #issueCommentCounts} with the latest counts.
     * Returns a list of issues which have new comments.
     * @return
     */
    private HashSet<Integer> updateIssueCommentCounts(boolean hasMetadata) {
        HashSet<Integer> result = new HashSet<>();
        for (TurboIssue issue : getIssueList()) {
            if (issueCommentCounts.containsKey(issue.getId())) {
                // We know about this issue; check if it's been updated
                if (issueHasNewComments(issue, hasMetadata)) {
                    result.add(issue.getId());
                }
            } else {
                // We don't know about this issue, just put the current comment count.
                issueNonSelfCommentCounts.put(issue.getId(), issue.getMetadata().getNonSelfCommentCount());
                issueCommentCounts.put(issue.getId(), issue.getCommentCount());
            }
        }
        return result;
    }

    @Override
    public void refreshItems(boolean hasMetadata) {
        super.refreshItems(hasMetadata);

        boolean hasUpdatedQualifier = currentFilterExpression.getQualifierNames().contains(Qualifier.UPDATED);

        // Only update filter if filter does not contain UPDATED (does not need to wait for metadata)
        // or if hasMetadata is true (metadata has arrived), or if getIssueList is empty (if filter does
        // have UPDATED, but there are no issues whose metadata require retrieval causing hasMetadata to
        // never be true)

        if (!hasUpdatedQualifier // not waiting for metadata, just update
                || hasMetadata // metadata has arrived, update
                || getIssueList().size() == 0 // checked only when above two not satisfied
                ) {
            final HashSet<Integer> issuesWithNewComments = updateIssueCommentCounts(hasMetadata);

            // Set the cell factory every time - this forces the list view to update
            listView.setCellFactory(list ->
                    new IssuePanelCell(model, IssuePanel.this, columnIndex, issuesWithNewComments));
            listView.saveSelection();

            // Supposedly this also causes the list view to update - not sure
            // if it actually does on platforms other than Linux...
            listView.setItems(null);
            listView.setItems(getIssueList());
            issueCount = getIssueList().size();

            listView.restoreSelection();
            this.setId(model.getDefaultRepo() + "_col" + columnIndex);
{'fraction_non_alphanumeric': 0.0851439182915506, 'fraction_numerical': 0.00046425255338904364, 'mean_word_length': 2.877249820014399, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5516072', 'n_tokens_mistral': 2779, 'n_tokens_neox': 2691, 'n_words': 765}