package sample.design_pattern;
public abstract boolean hasNext();
public abstract void next();
public abstract Object getValue
(); }
interface Aggregate {
}
private int value;
this.value = value;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}
private ElementList list;
private int index;
this.list = list;
this.index = 0;
}
public boolean hasNext() {
return (list.getLastNum() > index) ? true : false;
}
public void next() {
++index;
}
return list.getValueAt(index);
}
}
class ElementList implements Aggregate {
private int last = 0;
public ElementList(int count) {
}
list[last++] = element;
}
public Element getValueAt
(int index
) { return list[index];
}
public int getLastNum() {
return last;
}
}
}
public class IteratorPatternTest {
public static void main
(String[] args
) { ElementList list = new ElementList(5);
for (int i = 0; i < 5; ++i) {
}
for (Iterator it
= list.
iterator(); it.
hasNext(); it.
next()) { }
}
}
最終更新:2008年09月09日 19:45