public IRoad getNextElement(IMapElement _currentElement, boolean fToL) throws Exception {
if(_currentElement.getClass().equals(IRoad.class)){
IRoad currentElement = (IRoad) _currentElement;
ICrossRoad first = currentElement.getFCross();
ICrossRoad last = currentElement.getLCross();
ICrossRoad nextCross = this.getNextCross(first,last);
if (nextCross !=null){
if (nextCross.equals(first)&&!fToL){
return currentElement;
}
if (nextCross.equals(last)&&fToL){
return currentElement;
}
if (fToL){
return this.findRoad(first, nextCross);
}
if (!fToL){
return this.findRoad(last,nextCross);
}
throw new Exception("paths errors!!") ;
}else {
return null;
}
}else {
ICrossRoad currentElement = (ICrossRoad) _currentElement;
ICrossRoad nextCross = this.getNextCross(currentElement);
if (nextCross !=null){
if(nextCross.equals(currentElement)){
return this.getNextElement(currentElement, fToL);
}
return this.findRoad(currentElement,nextCross);
}else {
return null;