/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford Mount Allison University 2001 File: FunctorList.java Description: This class a list of functors */ import java.awt.*; class FunctorList //class functor_list definition { MainWindow ed; FunctorNode head; //Points to front of LinkedList FunctorNode tail; //Points to back of LinkedList public void FunctorList(MainWindow edit) //List Constructor { ed = edit; head = tail = null; } public void insertNode(FunctorNode f, TextArea t) //Inserts node at end of linked list { //getList(t); //FunctorNode temp = new FunctorNode(); Category A; Category B; Category diagram; CatFunctor cf; //getList(t); A = f.A; B = f.B; diagram = f.diagram; cf = f.f; //getList(t); //temp = f; if (isEmpty()) { head = tail = new FunctorNode(ed, A, B, diagram, cf); //t.append("IS EMPTY"); } else { tail = tail.next = new FunctorNode(ed, A, B, diagram, cf); //t.append("NOT EMPTY"); } //getList(t); } public void getList(TextArea view) //Retrieves list of functors in linked list { FunctorNode current = head; view.append("------------------\n"); while(current != null) { view.append("-> " + current.f.name + "\n"); current = current.next; } view.append("------------------\n\n"); } /* public void replaceNode(Category c) //Replaces a node with an updated version of the same node { FunctorNode current = head; while(current !=null) { if (c.name.equals(current.cat.name)) { current.cat = c; } current = current.next; } } */ public FunctorNode getNode(String name) { FunctorNode getItem = null; FunctorNode current = head; while(current !=null) { if (name.equals(current.f.name)) { return current; } current = current.next; } return getItem; //return null if category not in list } public boolean removeNode(String name) throws EmptyListException //Removes node from end of linked list { FunctorNode current = head; FunctorNode previous = null; if (isEmpty()) throw new EmptyListException(); if (name.equals(head.f.name)) { if (head.equals(tail)) head = tail = null; else head = head.next; return true; } else { while(current != null) { if (name.equals(current.next.f.name)) { previous = current; //previous is node before one being removed current = current.next; //current is node being removed previous.next = current.next; //previous.next points to current.next return true; } current = current.next; } } return false; } public boolean isEmpty() //Returns if the linked list is empty //That is, if the head of the list points to null { return (head == null); } }