假设DebateAssignment有类似的东西
public Collection getDebateTeams();
你想要一个Iterator< DebateTeam>?
如果是这样,你想要的东西如下:
public class DebateTeamIterator implements Iterator {
private Iterator iAssignment;
private Iterator iTeam;
public DebateTeamIterator(Iterator iAssignment) {
this.iAssignment = iAssignment;
if (iAssignment.hasNext())
iTeam = iAssignment.next().getDebateTeams().iterator();
else
iTeam = new LinkedList().iterator();
}
public boolean hasNext() {
return iTeam.hasNext() || iAssignment.hasNext();
}
public DebateTeam next() {
if (!iTeam.hasNext())
iTeam = iAssignment.next().getDebateTeams().iterator();
return iTeam.next();
}
// ... other methods removed for brevity...
}