package no.hioa.dape1400.s236758.HelperTools;

import java.util.ArrayList;


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

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

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

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

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

    public int getPreviousMenuID() {
        return this.getNextMenuID() - 1;
    }

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

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

@@ -57,25 +57,71 @@
 va.util.
-ArrayList
+HashMap;%0Aimport java.util.Map;%0Aimport java.util.Scanner
 ;%0A%0A%0A/**%0A
@@ -230,26 +230,29 @@
 private 
-ArrayList%3C
+Map%3CInteger, 
 Runnable
@@ -486,17 +486,15 @@
 new 
-ArrayList
+HashMap
 %3C%3E()
@@ -674,19 +674,19 @@
 methods.
-add
+put
 (this.ge
@@ -919,24 +919,29 @@
      return 
+this.
 methodSize ;
@@ -952,21 +952,22 @@
  %7D%0A    p
-ublic
+rivate
  Runnabl
@@ -1038,93 +1038,8 @@
  %7D%0A%0A
-    public int getPreviousMenuID() %7B%0A        return this.getNextMenuID() - 1;%0A    %7D%0A%0A
     
@@ -1114,21 +1114,22 @@
 %7D%0A%0A    p
-ublic
+rivate
  String 
@@ -1241,10 +1241,1290 @@
 ;%0A    %7D%0A
-%7D
 %0A
+    public void runMenu() %7B%0A        Scanner scanner = new Scanner(System.in) ;%0A        String input ;%0A        String finalDashboard ;%0A        int intForMenu ;%0A        boolean keepGoing = true ;%0A%0A        if(this.getMethodSize() == 0) %7B%0A            System.out.println(%22No menu items added..%22) ;%0A            return ;%0A        %7D%0A%0A        if(this.getMethodSize() %3E 1) %7B%0A            finalDashboard = String.format(%22%25s %5CnInput integer between 1 and %25d (or nothing, to quit) then press %5C%22Enter%5C%22%22,%0A                    dashboard.toString(), this.getMethodSize()) ;%0A        %7D else %7B%0A            finalDashboard = String.format(%22%25s %5CnInput integer 1 (or nothing) then press %5C%22Enter%5C%22%22,%0A                    dashboard.toString()) ;%0A        %7D%0A%0A        while(keepGoing) %7B%0A            System.out.println(finalDashboard);%0A            input = scanner.nextLine();%0A            if(input.toString().isEmpty()) %7B%0A                keepGoing = false ;%0A                continue ;%0A            %7D%0A%0A            if (input.matches(%22%5E%5B0-9%5D*%22)) %7B%0A                intForMenu = Integer.parseInt(input);%0A%0A                if(intForMenu %3C= this.getMethodSize()) %7B%0A                    this.getMethod(intForMenu).run();%0A                %7D%0A            %7D%0A%0A            System.out.println(%22Unrecognized input%22) ;%0A        %7D%0A    %7D%0A%7D

change ConsoleMenuHelper to provide all encompassing menu with Runnables