001package state.ui;
002
003import java.util.ArrayList;
004import java.util.List;
005
006public class UIMenuBuilder {
007        private final List<UIMenu.Pair> menu = new ArrayList<UIMenu.Pair>();
008        public UIMenu toUIMenu(String heading) {
009                if (null == heading)
010                        throw new IllegalArgumentException();
011                if (menu.size() <= 1)
012                        throw new IllegalStateException();
013                UIMenu.Pair[] array = new UIMenu.Pair[menu.size()];
014                for (int i = 0; i < menu.size(); i++)
015                        array[i] = menu.get(i);
016                return new UIMenu(heading, array);
017        }
018        public void add(String prompt, UIMenuAction action) {
019                if (null == action)
020                        throw new IllegalArgumentException();
021                menu.add(new UIMenu.Pair(prompt, action));
022        }
023}