public void addTimer(String timerNodeX, medNode medX, string pathNameX) { /* * Three Conditions * First Timer == null - No Timers - firstTimer = New Path * First Timer.getNext() == null - One Timer - firstTimer.getNext().setNext(New Timer) * First Timer.getNext() != null - > Two Timers - find last and assign */ if (firstTimer == null) { timerNode newTimer = new timerNode(timerNodeX, medX, pathNameX); firstTimer = newTimer; Console.ForegroundColor = ConsoleColor.DarkGray; M.debug("New Timer Created, assigned to firstTimer"); } else if (firstTimer.getNextTimer() == null) { timerNode newTimer = new timerNode(timerNodeX, medX, pathNameX); firstTimer.setNextTimer(newTimer); //firstTimer.next = newPath newTimer.setPrevTimer(firstTimer); M.debug("New Timer Created, registered as second Timer created"); } else { TS = firstTimer; while (TS.getNextTimer() != null) { //Find last path TS = TS.getNextTimer(); } timerNode newPath = new timerNode(timerNodeX, medX, pathNameX); TS.setNextTimer(newPath); //lastPath.next = newPath newPath.setPrevTimer(TS); //newPath.last = lastPath M.debug("Timer created, Unkown TImer possiton, Prev/Next Timer values assigned accordingly"); } }
public void removeTimer(timerNode 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 == firstTimer) //If the path to remove is the first path, you simple need to re-assign first path. { if (remove.getNextTimer() == null) //Program will error out w/o these error checks { firstTimer = null; } else { firstTimer = remove.getNextTimer(); firstTimer.setPrevTimer(null); } } else if (remove == firstTimer.getNextTimer()) /* * 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 firstTimer, I like to call it Directly */ { if (remove.getNextTimer() == null) { firstTimer.setNextTimer(null); remove.setPrevTimer(null); //This is a redudent clean up that I like to do, it is not necissary } else { firstTimer.setNextTimer(remove.getNextTimer()); remove.getNextTimer().setPrevTimer(firstTimer); remove.setNextTimer(null); remove.setPrevTimer(null); } } else { if (remove.getNextTimer() == null) { remove.getPrevTimer().setNextTimer(null); remove.setNextTimer(null); } else { remove.getPrevTimer().setNextTimer(remove.getNextTimer()); remove.getNextTimer().setPrevTimer(remove.getPrevTimer()); remove.setNextTimer(null); remove.setPrevTimer(null); } } }