Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyDiner{
- private string[] _menuitems;
- private int _position;
- private IEnumerable<string>[] _subMenus;
- private int _innerPosition;
- private IEnumerable _currentIterator;
- public MyDiner(ICollection<string> subMenus) : IEnumerable{
- _position = 0;
- _innerPosition = 0;
- _menuItems = new string[] {"Coffee", "Latte machiato", "Cappuchino"};
- _submenus = submenus
- _currentIterator = _submenus[_innerPosition].Iterator();
- }
- public bool HasNext(){
- return _innerPosition == _submenus.length - 1 || _currentIterator.HasNext();
- }
- public string Next(){
- if(_position < _menuitems.length){
- _position ++;
- return = __menuItems[_position - 1];
- }
- else if(_currentIterator.HasNext){
- return _currentIterator.Next();
- }
- else if (_innerPosition < _submenus.length -1){
- _innerPosition ++;
- _currentIterator = _submenus[_innerPosition].Iterator();
- return _currentIterator.Next();
- }
- else {
- thow new IllegalOperationException("I'm out of elements!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement