标签:
public interface Iterator { public Object next(); public boolean hasNext(); public boolean remove(); }
public class ConcreteIterator implements Iterator{ private Vector vector = new Vector(); public int cursor = 0; public ConcreteIterator(Vector vector){ this.vector = vector; } @Override public Object next() { Object result = null; if(hasNext()){ result = this.vector.get(cursor); }else{ result = null; } return result; } @Override public boolean hasNext() { if(cursor == vector.size()){ return false; }else{ return true; } } @Override public boolean remove() { vector.remove(cursor); return true; } }
public interface Aggregate { public void add(Object object); public void remove(Object object); public Iterator iterator(); }
public class ConcreteAggregate implements Aggregate{ private Vector vector = new Vector(); @Override public void add(Object object) { vector.add(object); } @Override public void remove(Object object) { } @Override public Iterator iterator() { return new ConcreteIterator(vector); } }
标签:
原文地址:http://blog.csdn.net/renpengddxx/article/details/52131516