Code example for Stack

Methods: empty, peek, pop, push

0
	public CompositeIterator(Iterator<MenuComponent> iterator) {
		stack.push(iterator);
	} 
 
	public boolean hasNext() { 
		if(stack.empty()) {
			return false; 
		} else { 
			Iterator<MenuComponent> iterator = stack.peek();
			if(!iterator.hasNext()) {
				stack.pop();
				return hasNext(); 
			} else { 
				return true; 
			} 
		} 
	} 
 
	public MenuComponent next() { 
		if(hasNext()) { 
			Iterator<MenuComponent> iterator = stack.peek();
			MenuComponent component = iterator.next();
			if (component instanceof Menu) {
				stack.push(component.createIterator());
			} 
			return component;
		} else { 
			return null; 
		}