<commit_before>package com.twu.biblioteca.controller;

import com.twu.biblioteca.model.*;
import com.twu.biblioteca.view.*;

import static com.twu.biblioteca.controller.AppController.State.*;

public class AppController {

    public enum State {
        Login,
        MainMenu, MainMenuInvalidOption,
        ListBooks, SuccessfulBookCheckout, UnsuccessfulBookCheckout,
        ReturnBooks, SuccessfulReturn, UnsuccessfulReturn,
        ListMovies, SuccessfulMovieCheckout,
        Finished
    }


    private State state;
    private BookCollection books;
    private MovieCollection movies;

    private AppState appState;

    public AppController(BookCollection books, MovieCollection movies) {
        this(books, movies, State.Login);
    }

    public AppController(BookCollection books, MovieCollection movies, State startState) {
        this.state = startState;
        this.books = books;
        this.movies = movies;


    }


    public Screen getCurrentScreen() {
        switch (state) {
            case Login:
                // This is only here because login is the default start screen
                if (appState == null) {
                    appState = new LoginState(books, movies);
                }
                return appState.getScreen();
            case MainMenu:
                return new MainMenuScreen();
            case MainMenuInvalidOption:
                return new InvalidOptionScreen();
            case ListBooks:
                return appState.getScreen();
            case ReturnBooks:
                return appState.getScreen();
            case ListMovies:
                return appState.getScreen();
            case Finished:
                return appState.getScreen();
            default:
                return null;
        }
    }


    public Screen getNextScreen(String input) {

        updateState(input);

        return getCurrentScreen();
    }


    private void updateState(String input) {

        switch (state) {
            case Login:
                if (appState == null) {
                    appState = new LoginState(books, movies);
                }

                appState = appState.nextState(input);
                if (appState instanceof MainMenuState) {
                    state = State.MainMenu;
                }
                break;

            case MainMenu:

                state = updateMainMenuState(input);

                if (state == ListBooks) {
                    appState = new BorrowBookState(books, movies);
                } else if (state == ReturnBooks) {
                    appState = new ReturnBookState(books, movies);
                } else if (state == ListMovies) {
                    appState = new BorrowMovieState(books, movies);
                } else if (state == Finished) {
                    appState = new QuitState(books, movies);
                }

                break;

            case MainMenuInvalidOption:

                state = State.MainMenu;
                break;

            case ListBooks:
                if (appState == null) {
                    appState = new BorrowBookState(books, movies);
                }

                appState = appState.nextState(input);
                if (appState instanceof MainMenuState) {
                    appState = null;
                    state = State.MainMenu;
                }
                break;

            case ReturnBooks:
                if (appState == null) {
                    appState = new ReturnBookState(books, movies);
                }

                appState = appState.nextState(input);
                if (appState instanceof MainMenuState) {
                    appState = null;
                    state = State.MainMenu;
                }
                break;

            case ListMovies:
                if (appState == null) {
                    appState = new BorrowMovieState(books, movies);
                }

                appState = appState.nextState(input);
                if (appState instanceof MainMenuState) {
                    appState = null;
                    state = State.MainMenu;
                }
                break;

            case Finished:

                if (appState == null) {
                    appState = new QuitState(books, movies);
                }

                appState = appState.nextState(input);
                break;

            default:

                state = State.MainMenu;
                break;
        }
    }


    private State updateMainMenuState(String input) {
        if (input.equals(MainMenuScreen.ListBooksOption)) {

            return State.ListBooks;

        } else if (input.equals(MainMenuScreen.ReturnBooksOption)) {

            return State.ReturnBooks;

        } else if (input.equals(MainMenuScreen.ListMoviesOption)) {

            return State.ListMovies;

        } else if (input.equals(MainMenuScreen.QuitOption)) {

            return State.Finished;

        } else {

            return State.MainMenuInvalidOption;
        }
    }
}<commit_msg>Finished moving logic out of AppController into AppState objects.<commit_after>package com.twu.biblioteca.controller;

import com.twu.biblioteca.model.*;
import com.twu.biblioteca.view.*;

import static com.twu.biblioteca.controller.AppController.State.*;

public class AppController {

    public enum State {
        Login,
        MainMenu,
        ListBooks,
        ReturnBooks,
        ListMovies,
        Finished
    }


    private State state;
    private BookCollection books;
    private MovieCollection movies;

    private AppState appState;

    public AppController(BookCollection books, MovieCollection movies) {
        this(books, movies, State.Login);
    }

    public AppController(BookCollection books, MovieCollection movies, State startState) {
        this.state = startState;
        this.books = books;
        this.movies = movies;

        switch (state) {
            case Login:
                appState = new LoginState(books, movies);
                break;
            case MainMenu:
                appState = new MainMenuState(books, movies);
                break;
            case ListBooks:
                appState = new BorrowBookState(books, movies);
                break;
            case ReturnBooks:
                appState = new ReturnBookState(books, movies);
                break;
            case ListMovies:
                appState = new BorrowMovieState(books, movies);
                break;
            case Finished:
                appState = new QuitState(books, movies);
                break;
            default:
                appState = null;
        }
    }


    public Screen getCurrentScreen() {
        return appState.getScreen();
    }

    public Screen getNextScreen(String input) {

        updateState(input);

        return getCurrentScreen();
    }


    private void updateState(String input) {
        appState = appState.nextState(input);
    }

}
{'fraction_non_alphanumeric': 0.07436483014558949, 'fraction_numerical': 0.0, 'mean_word_length': 1.4962593516209477, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5102619', 'n_tokens_mistral': 1809, 'n_tokens_neox': 1641, 'n_words': 417}