<commit_before>package tracker.start;

import tracker.models.Item;
import tracker.models.Task;

import java.util.HashMap;

/**
 * Menu class includes menu and responces for each part of it.
 *
 * @author <NAME> <EMAIL>
 * @version 1
 * @since 18.02.2017
 */
public class Menu {
    /**
     * Store menu chapters.
     */
    private static final String[] MENU = {
            "1. Вывести список заявок",
            "2. Добавить новую заявку",
            "3. Отредактировать заявку",
            "4. Удалить заявку",
            "5. Найти заявку по названию.",
            "6. Найти заявку по номеру",
            "7. Выйти из программы."
    };
    /**
     * Store tracker on that menu operates.
     */
    private Tracker tracker;
    /**
     * Store is menu must be exit.
     */
    private boolean isExit = false;
    /**
     * Store is menu must be shown after this action.
     */
    private boolean isShow = true;

    /**
     * Menu class constructor.
     *
     * @param tracker on that menu operates
     */
    public Menu(Tracker tracker) {
        this.tracker = tracker;
    }

    /**
     * Show menu.
     */
    public void show() {
        System.out.println("What do your want? Press a number from menu:");
        for (String s : this.MENU) {
            System.out.println(s);
        }
    }

    /**
     * Create new item by given name and description.
     *
     * @param input from for it will be get
     * @return Item to add
     */
    public Item createItem(Input input) {
        String name = input.ask("Enter brief summary of item (name of item):  ");
        String description = input.ask("Enter your full story (description of item):  ");
        return new Task(name, description);
    }

    /**
     * Choose item from tracker.
     *
     * @param input from for it will be get
     * @param ask   question for user
     * @return Item chosen item
     */
    public Item chooseItem(Input input, String ask) {
        Item result = null;
        HashMap<Integer, String> map = tracker.enumItems();
        if (!map.isEmpty()){
            result = tracker.findById(map.get(Integer.parseInt(input.ask(ask))));
        }
        return result;
    }

    /**
     * Choose item from tracker.
     *
     * @param input  from for it will be get
     * @param output to where will be shown important information
     */
    public void editItem(Input input, Output output) {
        Item itemForEdit = chooseItem(input, "Enter a number to choose item for edit");
        if (itemForEdit!=null) {
            String id = itemForEdit.getId();
            String name = itemForEdit.getName();
            String description = itemForEdit.getDescription();
            System.out.println("You are edited task with id = " + id);
            System.out.println("name = " + name);
            String newName = input.ask("Enter new name or just press Enter to stay current");
            if (!"".equals(newName)) {
                name = newName;
            }
            System.out.println("description now = " + description);
            String newDescription = input.ask("Enter new description or just press Enter to stay current");
            if (!"".equals(newDescription)) {
                description = newDescription;
            }
            Item itemForUpdate = new Task(name, description);
            itemForUpdate.setId(id);
            tracker.update(itemForUpdate);
        } else output.toOutput(new String[] {"Nothing to edit"});
    }

    /**
     * Dialog for delete item from tracker.
     *
     * @param input from for it will be get
     * @param output to where will be shown important information
     */
    public void deleteItem(Input input, Output output) {
        Item itemForDelete = chooseItem(input, "Enter a number to delete item");
        if (itemForDelete!=null) {
            tracker.delete(chooseItem(input, "Enter a number to delete item"));
        } else output.toOutput(new String[] {"Nothing to delete"});
    }

    /**
     * Show given items to output.
     *
     * @param items  that must be shown
     * @param output to where will be shown important information
     */
    public void showItems(Item[] items, Output output) {
        if(items.length != 0 && items[0]!=null) {
            for (Item item : items) {
                System.out.println("I'm here" );
                output.toOutput(new String[]{"Name: " + item.getName() + " Description: " + item.getDescription()});
            }
        } else output.toOutput(new String[]{"No items to show"});
    }

    /**
     * Return is menu must be exit.
     *
     * @return is menu must be exit
     */
    public boolean isExit() {
        return isExit;
    }

    /**
     * Return is menu must be shown after this action.
     *
     * @return is menu must be shown after this actio
     */
    public boolean isShow() {
        return isShow;
    }

    /**
     * User choosing - do something.<commit_msg>5.1 ended<commit_after>package tracker.start;

import tracker.models.Item;
import tracker.models.Task;

import java.util.HashMap;

/**
 * Menu class includes menu and responces for each part of it.
 *
 * @author <NAME> <EMAIL>
 * @version 1
 * @since 18.02.2017
 */
public class Menu {
    /**
     * Store menu chapters.
     */
    private static final String[] MENU = {
            "1. Вывести список заявок",
            "2. Добавить новую заявку",
            "3. Отредактировать заявку",
            "4. Удалить заявку",
            "5. Найти заявку по названию.",
            "6. Найти заявку по номеру",
            "7. Выйти из программы."
    };
    /**
     * Store tracker on that menu operates.
     */
    private Tracker tracker;
    /**
     * Store is menu must be exit.
     */
    private boolean isExit = false;
    /**
     * Store is menu must be shown after this action.
     */
    private boolean isShow = true;

    /**
     * Menu class constructor.
     *
     * @param tracker on that menu operates
     */
    public Menu(Tracker tracker) {
        this.tracker = tracker;
    }

    /**
     * Show menu.
     */
    public void show() {
        System.out.println("What do your want? Press a number from menu:");
        for (String s : this.MENU) {
            System.out.println(s);
        }
    }

    /**
     * Create new item by given name and description.
     *
     * @param input from for it will be get
     * @return Item to add
     */
    public Item createItem(Input input) {
        String name = input.ask("Enter brief summary of item (name of item):  ");
        String description = input.ask("Enter your full story (description of item):  ");
        return new Task(name, description);
    }

    /**
     * Choose item from tracker.
     *
     * @param input from for it will be get
     * @param ask   question for user
     * @return Item chosen item
     */
    public Item chooseItem(Input input, String ask) {
        Item result = null;
        HashMap<Integer, String> map = tracker.enumItems();
        if (!map.isEmpty()) {
            result = tracker.findById(map.get(Integer.parseInt(input.ask(ask))));
        }
        return result;
    }

    /**
     * Choose item from tracker.
     *
     * @param input  from for it will be get
     * @param output to where will be shown important information
     */
    public void editItem(Input input, Output output) {
        Item itemForEdit = chooseItem(input, "Enter a number to choose item for edit");
        if (itemForEdit != null) {
            String id = itemForEdit.getId();
            String name = itemForEdit.getName();
            String description = itemForEdit.getDescription();
            System.out.println("You are edited task with id = " + id);
            System.out.println("name = " + name);
            String newName = input.ask("Enter new name or just press Enter to stay current");
            if (!"".equals(newName)) {
                name = newName;
            }
            System.out.println("description now = " + description);
            String newDescription = input.ask("Enter new description or just press Enter to stay current");
            if (!"".equals(newDescription)) {
                description = newDescription;
            }
            Item itemForUpdate = new Task(name, description);
            itemForUpdate.setId(id);
            tracker.update(itemForUpdate);
        } else {
            output.toOutput(new String[]{"Nothing to edit"});
        }
    }

    /**
     * Dialog for delete item from tracker.
     *
     * @param input  from for it will be get
     * @param output to where will be shown important information
     */
    public void deleteItem(Input input, Output output) {
        Item itemForDelete = chooseItem(input, "Enter a number to delete item");
        if (itemForDelete != null) {
            tracker.delete(chooseItem(input, "Enter a number to delete item"));
        } else {
            output.toOutput(new String[]{"Nothing to delete"});
        }
    }

    /**
     * Show given items to output.
     *
     * @param items  that must be shown
     * @param output to where will be shown important information
     */
    public void showItems(Item[] items, Output output) {
        if (items.length != 0 && items[0] != null) {
            for (Item item : items) {
                System.out.println("I'm here");
                output.toOutput(new String[]{"Name: " + item.getName() + " Description: " + item.getDescription()});
            }
        } else {
            output.toOutput(new String[]{"No items to show"});
        }
    }

    /**
     * Return is menu must be exit.
     *
     * @return is menu must be exit
     */
    public boolean isExit() {
        return isExit;
    }

    /**
     * Return is menu must be shown after this action.
     *
     * @return is menu must be shown after this actio
     */
    public boolean isShow() {
        return isShow;
    }

    /**
     * User choosing - do something.
{'fraction_non_alphanumeric': 0.10836995605273672, 'fraction_numerical': 0.0037954454654414702, 'mean_word_length': 1.8864226001729605, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4226986', 'n_tokens_mistral': 2815, 'n_tokens_neox': 2758, 'n_words': 934}