@Override public Object Next() { Object rect = null; current++; if (current < aggregate.count()) { rect = aggregate.get(current); } return rect; }
public static void main(String[] args) { ConcreteAggregate aggregate = new ConcreteAggregate(); aggregate.set(0, "哈哈0"); aggregate.set(1, "哈哈1"); aggregate.set(2, "哈哈2"); aggregate.set(3, "哈哈3"); aggregate.set(4, "哈哈4"); aggregate.set(5, "哈哈5"); Iterator i = new ConcreteIterator(aggregate); Object item = i.First(); while (!i.IsDone()) { System.out.println(i.CurrentItem() + "请买票"); i.Next(); } }
@Override public Object CurrentItem() { return aggregate.get(current); }
@Override public boolean IsDone() { return current >= aggregate.count() ? true : false; }
@Override public Object First() { return aggregate.get(0); }