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