2 * Copyright (C) 2015 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.addressbook.menu;
19 import java.util.Iterator;
21 import org.apache.logging.log4j.Logger;
22 import org.mxchange.addressbook.BaseAddressbookSystem;
23 import org.mxchange.addressbook.menu.item.SelectableMenuItem;
27 * @author Roland Haeder
29 public class MenuTools extends BaseAddressbookSystem {
32 * Gets an array with all available access keys back from given menu map.
33 * This can later be handle to the client's enterChar() method.
35 * @param menus A Map with all menus and their entries
36 * @param menuType Menu type
37 * @return An array with available access chars
39 public static char[] getAccessKeysFromMenuMap (final Map<String, Menu> menus, final String menuType) {
41 Logger logger = new MenuTools().getLogger();
43 // First search for the proper menu class
44 Menu menu = menus.get(menuType);
47 if (!(menu instanceof Menu)) {
49 // @todo Rewrite to exception
50 logger.error("Menu '" + menuType + "' not found.");
55 Iterator<SelectableMenuItem> iterator = menu.getMenuItemsIterator();
57 // Init return array and counter 'i'
58 char[] accessKeys = new char[menu.getMenuItemsCount()];
61 // Now "walk" through all menu entries
62 while (iterator.hasNext()) {
64 SelectableMenuItem item = iterator.next();
65 //* NOISY-DEBUG: */ logger.debug("item=" + item);
67 // Get access key from item and add it to the array
68 accessKeys[i] = item.getAccessKey();
69 //* NOISY-DEBUG: */ logger.debug("accessKeys[" + i + "]=" + accessKeys[i]);
75 // Return finished array