public void addPath(String pathNameX) { /* * Three Conditions * First Path == null - No Paths - FirstPath = New Path * First Path.getNext() == null - One Path - FirstPath.getNext().setNext(New Path) * First path.getNext() != null - > Two Path - find last and assign */ if (firstPath == null) { pathNode newPath = new pathNode(pathNameX); firstPath = newPath; Console.ForegroundColor = ConsoleColor.DarkGray; M.debug("New Path Created, assigned to firstPath"); } else if (firstPath.getNextPath() == null) { pathNode newPath = new pathNode(pathNameX, firstPath); firstPath.setNextpath(newPath); //firstPath.next = newPath newPath.setPrevpath(firstPath); M.debug("New path Created, registered as second path created"); } else { PS = firstPath; while (PS.getNextPath() != null) { //Find last path PS = PS.getNextPath(); } pathNode newPath = new pathNode(pathNameX); PS.setNextpath(newPath); //lastPath.next = newPath newPath.setPrevpath(PS); //newPath.last = lastPath M.debug("Path created, Unkown path possiton, Prev/Next Path values assigned accordingly"); } }
public void removePath(pathNode remove) { /* * The getters for pathNodes are not build to not return null, meaning if you try and call a method like * remove.getNext().setNext(null) but remove.getNext() is null it will hard error */ if (remove == firstPath) //If the path to remove is the first path, you simple need to re-assign first path. { if (remove.getNextPath() == null) //Program will error out w/o these error checks { firstPath = null; } else { firstPath = remove.getNextPath(); firstPath.setPrevpath(null); } } else if (remove == firstPath.getNextPath()) /* * This is a simi-redundent case * This could be handled with the else statment * however I like handling this case seperatly I don't know why * Anyt thing I mess with anything to do with firstPath, I like to call it Directly */ { if (remove.getNextPath() == null) { firstPath.setNextpath(null); remove.setPrevpath(null); //This is a redudent clean up that I like to do, it is not necissary } else { firstPath.setNextpath(remove.getNextPath()); remove.getNextPath().setPrevpath(firstPath); remove.setNextpath(null); remove.setPrevpath(null); } } else { if (remove.getNextPath() == null) { remove.getPrevPath().setNextpath(null); remove.setNextpath(null); } else { remove.getPrevPath().setNextpath(remove.getNextPath()); remove.getNextPath().setPrevpath(remove.getPrevPath()); remove.setNextpath(null); remove.setPrevpath(null); } } }