In one file i have this:
public DirectoryNode(String n, List<FileSystemNode> c) {
...
private List<FileSystemNode> nodes;
...
public Iterator<FileSystemNode> iterator() { return nodes.iterator(); }
...}
And in another file, I have this:
public class SizeVisitor implements FileSystemVisitor<Integer>
{...
public Integer visitDirectory(DirectoryNode d){
}
}
My question is, how do I, in the visitDirectory make a for loop, which will take the iterator for d, and go through all the elements, and then on each element call the method “getSize”, which is implemented in FileSystemNode?
Thanks you very much for your help.
You might want to do something like this:
You can also make your
DirectoryNodeimplement the Iterable interface so you can use the foreach loop: