//StringLinkedListWithIteratorDemo.java

//Public methods in the StringLinkedListWithIterator class:
//addANodeToStart()
//resetIteration()
//moreToIterate()
//goToNext()
//getDataAtCurrent()
//setDataAtCurrent()
//insertNodeAfterCurrent()
//deleteCurrentNode()
//showList()
//length()
//onList()
//toArray()

import java.util.Scanner;

public class StringLinkedListWithIteratorDemo
{
    public static void main(String[] args)
    {
        StringLinkedListWithIterator list = new StringLinkedListWithIterator();
        list.addANodeToStart("One");
        list.addANodeToStart("Two");
        list.addANodeToStart("Three");
        list.addANodeToStart("Four");
        list.addANodeToStart("Five");
        System.out.println("List has " + list.length() + " entries.");
        System.out.println("Showing current list contents:");
        list.showList();
        pause();

        System.out.println();
        if (list.onList("Three"))
            System.out.println("Three is on list.");
        else
            System.out.println("Three is NOT on list.");

        try
        {
            list.resetIteration();
            System.out.println("Current node data: " +
                list.getDataAtCurrent());
                
            list.goToNext();
            list.goToNext();
            System.out.println("Current node data: " +
                list.getDataAtCurrent());
            list.deleteCurrentNode();
            if (list.onList("Three"))
                System.out.println("Three is on list.");
            else
                System.out.println("Three is NOT on list.");
            System.out.println("Current node data: " +
                list.getDataAtCurrent());
            System.out.println("Showing current list contents:");
            list.showList();
            pause();

            list.resetIteration();
            while (list.moreToIterate())
            {
                System.out.println(list.getDataAtCurrent());
                list.goToNext();
            }
            System.out.println(list.getDataAtCurrent());
        }
        catch (LinkedListException e)
        {
            System.out.println(e.getMessage());
        }
        System.out.println("Carrying on ... ");
        pause();
        list.resetIteration();
        list.goToNext();
        list.insertNodeAfterCurrent("ten");
        list.showList();
        pause();
	}

    private static void pause()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.print("Press Enter to continue ... ");
        keyboard.nextLine();
    }
}

