package path;

import java.util.Iterator;

public class ConcretePath implements Path{
    Iterator<String> pathIterator;
    int length;

    public ConcretePath(Iterator<String> pathIterator) {
        this.pathIterator = pathIterator;
        this.length = length();
    }

    @Override
    public Iterator<String> getPathIterator() {
        return pathIterator;
    }

    @Override
    public int length() {
        length = 0;
        while(pathIterator.hasNext()){
            length++;
            pathIterator.next();
        }
        return length;
    }
}

package path;

import java.util.ArrayList;
import java.util.Iterator;

public class ConcretePath implements Path{
    private ArrayList<String> pathArray;

    public ConcretePath(ArrayList<String> pathArray) {
        this.pathArray = pathArray;
    }

    @Override
    public Iterator<String> getPathIterator() {
        return pathArray.iterator();
    }

    @Override
    public int length() {
        return pathArray.size();

    }
}

return Iterator from ArrayList.