001package myproject.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 void add(String prompt, UIMenuAction action) {
009                if (null == action)
010                        throw new IllegalArgumentException();
011                menu.add(new UIMenu.Pair(prompt, action));
012        }
013        public UIMenu toUIMenu(String heading) {
014                if (null == heading)
015                        throw new IllegalArgumentException();
016                if (menu.size() <= 1)
017                        throw new IllegalStateException();
018                UIMenu.Pair[] array = new UIMenu.Pair[menu.size()];
019                for (int i = 0; i < menu.size(); i++)
020                        array[i] = menu.get(i);
021                return new UIMenu(heading, array);
022        }
023}