2 * Copyright (C) 2016 - 2024 Free Software Foundation
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.text.MessageFormat;
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.Iterator;
23 import java.util.List;
24 import org.mxchange.addressbook.BaseAddressbookSystem;
25 import org.mxchange.addressbook.menu.item.SelectableMenuItem;
26 import org.mxchange.jcore.client.Client;
29 * A general menu class
31 * @author Roland Häder<roland@mxchange.org>
33 public abstract class BaseMenu extends BaseAddressbookSystem implements Menu {
38 private List<SelectableMenuItem> menuList;
41 * No instance from this object
43 protected BaseMenu () {
47 public int getMenuItemsCount () {
48 return this.menuList.size();
52 public Iterator<SelectableMenuItem> getMenuItemsIterator () {
53 return this.menuList.iterator();
57 public void show (final Client client) {
59 this.getLoggerBeanLocal().logTrace(MessageFormat.format("client={0} CALLED!", client)); //NOI18N
61 // Client must not be null
64 throw new NullPointerException("client is null"); //NOI18N
68 Iterator<SelectableMenuItem> iterator = this.menuList.iterator();
71 this.getLoggerBeanLocal().logDebug("Showing menu with '" + this.menuList.size() + "' entries.");
74 while (iterator.hasNext()) {
76 SelectableMenuItem item = iterator.next();
83 this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N
87 * Getter for menu list
89 * @return menuList List of menu entries
91 protected List<SelectableMenuItem> getMenuList () {
92 return Collections.unmodifiableList(this.menuList);
98 * @param menuType Menu type to initialize
99 * @param client CLient to call back
101 protected void initMenu (final String menuType, final Client client) {
103 this.getLoggerBeanLocal().logTrace(MessageFormat.format("menuType={0},client={1} - CALLED!", menuType, client)); //NOI18N
106 this.menuList = new ArrayList<>(5);
109 this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N