package no.hioa.dape1400.s236758.HelperTools;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;


/**
 * Created by dags on 20.08.15.
 */
public class ConsoleMenuHelper {
    private int nextMenuID ;
    private Map<Integer, Runnable> methods ;
    private int methodSize ;
    private StringBuilder dashboard ;

    public ConsoleMenuHelper(String menuName) {
        this.dashboard = new StringBuilder().append(menuName).append("\n");
        this.methods = new HashMap<>() ;
        this.nextMenuID = 1 ;
    }

    public void addItem(String menuText, Runnable methodName) {
        this.dashboard.append(menuItemText(menuText)) ;
        this.methods.put(this.getNextMenuID(), methodName);
        this.increaseNextMenuID();
    }

    public int getNextMenuID() {
        return this.nextMenuID;
    }

    public int getMethodSize() {
        this.methodSize = this.methods.size() ;
        return this.methodSize ;
    }
    private Runnable getMethod(int index) {
        return methods.get(index) ;
    }

    private void increaseNextMenuID() {
        this.nextMenuID ++;
    }

    private String menuItemText(String itemText) {
        return String.format("\t%d) %s\n",this.getNextMenuID(), itemText);
    }

    public void runMenu() {
        Scanner scanner = new Scanner(System.in) ;
        String input ;
        String finalDashboard ;
        int intForMenu ;
        boolean keepGoing = true ;

        if(this.getMethodSize() == 0) {
            System.out.println("No menu items added..") ;
            return ;
        }

        if(this.getMethodSize() > 1) {
            finalDashboard = String.format("%s \nInput integer between 1 and %d (or nothing) then press \"Enter\"",
                    dashboard, this.getMethodSize()) ;
        } else {
            finalDashboard = String.format("%s \nInput integer 1 (or nothing) then press \"Enter\"",
                    dashboard) ;
        }

        while(keepGoing) {
            System.out.println(finalDashboard);
            input = scanner.nextLine();
            if(input.toString().isEmpty()) {
                keepGoing = false ;
                continue ;
            }

            if (input.matches("^[0-9]*")) {
                intForMenu = Integer.parseInt(input);

                if(intForMenu <= this.getMethodSize()) {
                    this.getMethod(intForMenu).run();
                }
            }

            System.out.println("Unrecognized input") ;
        }
    }
}
@@ -267,37 +267,8 @@
 s ;%0A
-    private int methodSize ;%0A
     
@@ -843,25 +843,14 @@
     
-this.methodSize =
+return
  thi
@@ -872,41 +872,8 @@
 ) ;%0A
-        return this.methodSize ;%0A
     

remove methodSize column from ConsoleMenuHelper class. maintain functionality through getMethodSize()