Datasets:
ArXiv:
License:
| package Composite; | |
| import java.util.ArrayList; | |
| import java.util.Iterator; | |
| /** | |
| * Created by Administrator on 2017/7/12. | |
| */ | |
| public class Menu extends MenuComponent | |
| { | |
| private ArrayList<MenuComponent> menuComponents; | |
| private String name; | |
| private String description; | |
| public Menu(String name, String description) | |
| { | |
| menuComponents = new ArrayList<>(); | |
| this.name = name; | |
| this.description = description; | |
| } | |
| public void add(MenuComponent menuComponent) | |
| { | |
| menuComponents.add(menuComponent); | |
| } | |
| public void remove(MenuComponent menuComponent) | |
| { | |
| menuComponents.remove(menuComponent); | |
| } | |
| public MenuComponent getChild(int i) | |
| { | |
| return menuComponents.get(i); | |
| } | |
| public String getName() | |
| { | |
| return name; | |
| } | |
| public String getDescription() | |
| { | |
| return description; | |
| } | |
| public void print() | |
| { | |
| System.out.println(toString()); | |
| System.out.println("---------------------------"); | |
| Iterator iterator = menuComponents.iterator(); | |
| while (iterator.hasNext()) | |
| { | |
| MenuComponent menuComponent = (MenuComponent) iterator.next(); | |
| menuComponent.print(); | |
| } | |
| } | |
| public String toString() | |
| { | |
| return "Menu{" + | |
| "name='" + name + '\'' + | |
| ", description='" + description + '\'' + | |
| '}'; | |
| } | |
| public Iterator createIterator() | |
| { | |
| return new CompositeIterator(menuComponents.iterator()); | |
| } | |
| } | |