ListNode<Key,Value> createNode(Page<ListNode<Key,Value>> page) throws IOException { ListNode<Key,Value> node = new ListNode<Key,Value>(); node.setPage(page); page.set(node); node.setContainingList(this); return node; }
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public ListNode<Key, Value> readPayload(DataInput is) throws IOException { ListNode<Key, Value> node = new ListNode<Key, Value>(); node.setNext(is.readLong()); final short size = is.readShort(); for (short i = 0; i < size; i++) { node.entries.addLast(new KeyValueEntry(keyMarshaller.readPayload(is), valueMarshaller.readPayload(is))); } return node; } }
public void yourMainMethod() { ListNode head = new ListNode("Overflow!", null); head = new ListNode("Stack", head); head = new ListNode("in", head); head = new ListNode("is", head); head = new ListNode("This", head); printList(head); System.out.println(); printList(head); } //note different name, to clarify this is a separate reference public static void printList(ListNode node) { while(node != null) { System.out.print(node.getValue()+" "); node = node.getNext(); //node.setValue(new Object());//note that this would change the state inside the ListNode passed in } }
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public ListNode<Key, Value> readPayload(DataInput is) throws IOException { ListNode<Key, Value> node = new ListNode<Key, Value>(); node.setNext(is.readLong()); final short size = is.readShort(); for (short i = 0; i < size; i++) { node.entries.addLast(new KeyValueEntry(keyMarshaller.readPayload(is), valueMarshaller.readPayload(is))); } return node; } }
ListNode<Key,Value> createNode(Page<ListNode<Key,Value>> page) throws IOException { ListNode<Key,Value> node = new ListNode<Key,Value>(); node.setPage(page); page.set(node); node.setContainingList(this); return node; }
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public ListNode<Key, Value> readPayload(DataInput is) throws IOException { ListNode<Key, Value> node = new ListNode<Key, Value>(); node.setNext(is.readLong()); final short size = is.readShort(); for (short i = 0; i < size; i++) { node.entries.addLast(new KeyValueEntry(keyMarshaller.readPayload(is), valueMarshaller.readPayload(is))); } return node; } }
ListNode<Key,Value> createNode(Page<ListNode<Key,Value>> page) throws IOException { ListNode<Key,Value> node = new ListNode<Key,Value>(); node.setPage(page); page.set(node); node.setContainingList(this); return node; }
ListNode<Key,Value> createNode(Page<ListNode<Key,Value>> page) throws IOException { ListNode<Key,Value> node = new ListNode<Key,Value>(); node.setPage(page); page.set(node); node.setContainingList(this); return node; }
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public ListNode<Key, Value> readPayload(DataInput is) throws IOException { ListNode<Key, Value> node = new ListNode<Key, Value>(); node.setNext(is.readLong()); final short size = is.readShort(); for (short i = 0; i < size; i++) { node.entries.addLast(new KeyValueEntry(keyMarshaller.readPayload(is), valueMarshaller.readPayload(is))); } return node; } }
public void addToBack(String name, String telephoneNum, String email, String address, String dob) { //separate responsibilities, by constructing the node first addToBack(new ListNode(name,telephoneNum,email,address,dob)); } public void addToBack(ListNode newNode) { //do not use a continuation state in a class, fetch the head, inspect the head and if not null pass to the recursion method if(this.head == null) { this.head = newNode; } else { this.addToBack(this.head,newNode); } } public void addToBack(ListNode current, ListNode newNode) { //generic method that adds the node at the end if(current.getNext() == null) {//base case: current is the last node current.setNext(newNode); } else {//recursive case, current is not the next node addToBack(current.getNext(),newNode); } }