package uk.co.johnjtaylor.structures;

import java.util.ArrayList;

public class LinkedListNode<T extends Comparable<T>> extends DataStructures<T> {
	private T value;
	private LinkedListNode<T> nextNode;
	
	/**
	 * Construct a new LinkedListNode
	 * @param value Value of the node
	 * @param nextNode The next node of the list
	 */
	public LinkedListNode(T value, LinkedListNode<T> nextNode) {
		this.value = value;
		this.nextNode = nextNode;
	}

	/**
	 * @return the value
	 */
	public T getValue() {
		return value;
	}
	
	/**
	 * Set the value of a LinkedListNode @ runtime
	 * @param val new Value to be set
	 */
	public void setValue(T val) {
		this.value = val;
	}
	
	/**
	 * @return the nextNode
	 */
	public LinkedListNode<T> getNextNode() {
		return nextNode;
	}
	
	/**
	 * Sets the next node
	 */
	public void setNext(LinkedListNode<T> newNext) {
		this.nextNode = newNext;
	}

	@SuppressWarnings("unchecked") // It is checked reversely
	@Override
	public T[] toArray(Object inputData) {
		if(!(inputData instanceof LinkedListNode)) {
			throw new IllegalArgumentException("Linked List Node toArray() only accepts Linked List Nodes as input");
		}
		
		LinkedListNode<T> node = (LinkedListNode<T>) inputData;
		ArrayList<T> nodeList = new ArrayList<T>();
		while(node != null) {
			nodeList.add(node.getValue());
			node = node.getNextNode();
		}
		
		return (T[]) nodeList.toArray();
	}
	
	
}

@@ -1204,20 +1204,16 @@
 ;%0D%0A%09%09%7D%0D%0A
-%09%09%0D%0A
 %09%09Linked
@@ -1406,16 +1406,115 @@
 ;%0D%0A%09%09%7D%0D%0A
+%09%09Comparable%3C?%3E%5B%5D nodeArray = new Comparable%3C?%3E%5BnodeList.size()%5D;%0D%0A%09%09nodeList.toArray(nodeArray);%0D%0A
 %09%09%0D%0A%09%09re
@@ -1532,22 +1532,13 @@
 node
-List.to
 Array
-()
 ;%0D%0A%09
@@ -1546,11 +1546,14 @@
 %0D%0A%09%0D%0A%09%0D%0A
+%09%0D%0A
 %7D%0D%0A

Correct Object->Comparable cast errors in toArray