--- /dev/null
+/*\r
+ * Copyright (C) 2015 Roland Haeder\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package org.mxchange.addressbook.menu;\r
+\r
+import java.util.Iterator;\r
+import java.util.Map;\r
+import org.apache.logging.log4j.Logger;\r
+import org.mxchange.addressbook.BaseFrameworkSystem;\r
+import org.mxchange.addressbook.menu.item.SelectableMenuItem;\r
+\r
+/**\r
+ *\r
+ * @author Roland Haeder\r
+ */\r
+public class MenuTools extends BaseFrameworkSystem {\r
+\r
+ /**\r
+ * Gets an array with all available access keys back from given menu map.\r
+ * This can later be handle to the client's enterChar() method.\r
+ *\r
+ * @param menus A Map with all menus and their entries\r
+ * @param menuType Menu type\r
+ * @return An array with available access chars\r
+ */\r
+ public static char[] getAccessKeysFromMenuMap (final Map<String, Menu> menus, final String menuType) {\r
+ // Get logger\r
+ Logger logger = new MenuTools().getLogger();\r
+\r
+ // First search for the proper menu class\r
+ Menu menu = menus.get(menuType);\r
+\r
+ // Is it there?\r
+ if (!(menu instanceof Menu)) {\r
+ // Not found\r
+ // @todo Rewrite to exception\r
+ logger.error("Menu '" + menuType + "' not found.");\r
+ System.exit(1);\r
+ }\r
+\r
+ // Get iterator\r
+ Iterator<SelectableMenuItem> iterator = menu.getMenuItemsIterator();\r
+\r
+ // Init return array and counter 'i'\r
+ char[] accessKeys = new char[menu.getMenuItemsCount()];\r
+ int i = 0;\r
+\r
+ // Now "walk" through all menu entries\r
+ while (iterator.hasNext()) {\r
+ // Get item\r
+ SelectableMenuItem item = iterator.next();\r
+ //* NOISY-DEBUG: */ logger.debug("item=" + item);\r
+\r
+ // Get access key from item and add it to the array\r
+ accessKeys[i] = item.getAccessKey();\r
+ //* NOISY-DEBUG: */ logger.debug("accessKeys[" + i + "]=" + accessKeys[i]);\r
+\r
+ // Increment counter\r
+ i++;\r
+ }\r
+\r
+ // Return finished array\r
+ return accessKeys;\r
+ }\r
+}\r