<commit_before>package backend;

import backend.github.GitHubSource;
import backend.interfaces.RepoSource;
import backend.interfaces.RepoStore;
import backend.json.JSONStore;
import backend.json.JSONStoreStub;
import backend.resource.Model;
import backend.resource.serialization.SerializableModel;
import backend.stub.DummySource;
import org.apache.logging.log4j.Logger;
import ui.UI;
import util.HTLog;

import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import static util.Futures.withResult;

public class RepoIO {

    private static final Logger logger = HTLog.get(RepoIO.class);

    private final RepoSource repoSource;
    private final JSONStore jsonStore;

    private List<String> storedRepos;

    public RepoIO(boolean isTestMode, boolean enableTestJSON) {
        if (isTestMode) {
            repoSource = new DummySource();
            RepoStore.enableTestDirectory();
        } else {
            repoSource = new GitHubSource();
        }
        if (isTestMode && !enableTestJSON) {
            jsonStore = new JSONStoreStub();
            storedRepos = new ArrayList<>();
        } else {
            jsonStore = new JSONStore();
            storedRepos = new ArrayList<>(jsonStore.getStoredRepos());
        }
    }

    public List<String> getStoredRepos() {
        return storedRepos;
    }

    public CompletableFuture<Boolean> login(UserCredentials credentials) {
        return repoSource.login(credentials);
    }

    public CompletableFuture<Boolean> isRepositoryValid(String repoId) {
        return repoSource.isRepositoryValid(repoId);
    }

    public CompletableFuture<Model> openRepository(String repoId) {
        if (storedRepos.contains(repoId)) {
            return loadRepoFromStoreAsync(repoId)
                    .exceptionally(e -> {
                        return downloadRepoFromSourceBlocking(repoId);
                    });
        } else {
            return downloadRepoFromSourceAsync(repoId);
        }
    }

    private CompletableFuture<Model> loadRepoFromStoreAsync(String repoId) {
        return jsonStore.loadRepository(repoId)
                .thenCompose(this::updateModel);
    }<commit_msg>added lambda for openRepository in RepoIO<commit_after>package backend;

import backend.github.GitHubSource;
import backend.interfaces.RepoSource;
import backend.interfaces.RepoStore;
import backend.json.JSONStore;
import backend.json.JSONStoreStub;
import backend.resource.Model;
import backend.resource.serialization.SerializableModel;
import backend.stub.DummySource;
import org.apache.logging.log4j.Logger;
import ui.UI;
import util.HTLog;

import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import static util.Futures.withResult;

public class RepoIO {

    private static final Logger logger = HTLog.get(RepoIO.class);

    private final RepoSource repoSource;
    private final JSONStore jsonStore;

    private List<String> storedRepos;

    public RepoIO(boolean isTestMode, boolean enableTestJSON) {
        if (isTestMode) {
            repoSource = new DummySource();
            RepoStore.enableTestDirectory();
        } else {
            repoSource = new GitHubSource();
        }
        if (isTestMode && !enableTestJSON) {
            jsonStore = new JSONStoreStub();
            storedRepos = new ArrayList<>();
        } else {
            jsonStore = new JSONStore();
            storedRepos = new ArrayList<>(jsonStore.getStoredRepos());
        }
    }

    public List<String> getStoredRepos() {
        return storedRepos;
    }

    public CompletableFuture<Boolean> login(UserCredentials credentials) {
        return repoSource.login(credentials);
    }

    public CompletableFuture<Boolean> isRepositoryValid(String repoId) {
        return repoSource.isRepositoryValid(repoId);
    }

    public CompletableFuture<Model> openRepository(String repoId) {
        if (storedRepos.contains(repoId)) {
            return loadRepoFromStoreAsync(repoId)
                    .exceptionally(e -> downloadRepoFromSourceBlocking(repoId));
        } else {
            return downloadRepoFromSourceAsync(repoId);
        }
    }

    private CompletableFuture<Model> loadRepoFromStoreAsync(String repoId) {
        return jsonStore.loadRepository(repoId)
                .thenCompose(this::updateModel);
    }
{'fraction_non_alphanumeric': 0.08673007246376811, 'fraction_numerical': 0.0004528985507246377, 'mean_word_length': 3.0191082802547773, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3932064', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1198, 'n_words': 248}