// LinkedNodeCollection class - modified from
// LinkedCollection class from Data Structures and the 
// Java Collections Framework by W. J. Collins (downloaded from web site).
//
// Modified by Alyce Brady, 25 October 2002
//      Added numElts instance variable.
//      Modified the add method to use new Entry constructor (see below).
//      Removed implementations for methods covered in the mini-lab.
//      Added partial implementation of toString method.
//      Added partial implementation of equals method.
//      Made LinkedCollectionIterator public so it can be used by
//          CircularLCIterator.
//      Added lastReturned field to LinkedCollectionIterator.
//      Modified Entry class to add two-parameter constructor.
// 
// Modified by Pam Cutter, June 30, 2003
//	Modified to use the AP ListNode class instead of Entry

import java.util.*;

public class LinkedNodeCollection implements Collection
{
    protected ListNode head;
    protected int   numElts;   // number of elements; not in Collins's version

  // constructor

    /** Constructs an instance of a LinkedCollection. **/
    public LinkedNodeCollection()
        {   head = null;    }


  // observer methods implemented in LC Implementation Mini-Lab #1

    /** Returns the number of elements in this collection. **/
    public int size() 
    {   throw new UnsupportedOperationException( );     }


    /** Returns true if this collection is empty; returns false otherwise. **/
    public boolean isEmpty() 
    {   throw new UnsupportedOperationException( );     }


    /** Returns true if there is at least one element in this
     *  collection that is equal to o; otherwise, returns false.
     **/
    public boolean contains (Object o)
    {   throw new UnsupportedOperationException( );     }


    /** Returns an iterator for stepping through this collection. **/
    public Iterator iterator()
    {   throw new UnsupportedOperationException( );     }


  // observer methods implemented in LC Implementation Programming Project

    /** Returns a string represetation of this collection. **/
    public String toString()
    {
        String s = "[";
        if ( head == null )
            s += " ";
        else
        {
            s += head.getValue();

            // <code missing to add other elements, separated by commas>

        }
        s += "]";
        return s;
    }


    public Object[] toArray()
    {   throw new UnsupportedOperationException( );     }

    // you do not have to implement this method unless you want to
    public Object[] toArray(Object a[])
    {   throw new UnsupportedOperationException( );     }

    public boolean containsAll(Collection c)
    {   throw new UnsupportedOperationException( );     }

    public boolean addAll(Collection c)
    {   throw new UnsupportedOperationException( );     }

    public boolean removeAll(Collection c)
    {   throw new UnsupportedOperationException( );     }

    public boolean retainAll(Collection c)
    {   throw new UnsupportedOperationException( );     }

    public boolean equals(Object o)
    {
        // Make sure that we are comparing two LinkedCollections.
        if ( ! (o instanceof LinkedNodeCollection) )
            return false;
        LinkedNodeCollection other = (LinkedNodeCollection) o;

        // Compare all the individual elements in the two collections.
        ListNode node1, node2;
        for ( node1 = head, node2 = other.head; 
              node1 != null && node2 != null;
              node1 = node1.getNext(), node2 = node2.getNext() )
        {
            // <code missing to compare elements>
        }
        
        // Make sure that both collections were the same length.
        // <code missing to do this>

        return true;
    }


    // you do not have to implement this method unless you want to
    public int hashCode()
    {   throw new UnsupportedOperationException( );     }


  // modifier methods 
  //   (some will be implemented in Mini-Lab #2 or Programming Project)

    /** Inserts o at the front of this collection and returns true. **/
    public boolean add (Object o)
    {
        head = new ListNode(o, head);
        numElts++;
        return true;
    }


    /** Removes o from this collection and returns true (if o was in the
     *  collection to start with), or returns false and leaves the collection
     *  unchanged (if o was not in the collection to start with).  If the
     *  collection contained duplicate copies of object o to start with,
     *  only the first one is removed.
     **/
    public boolean remove(Object o) 
    {   throw new UnsupportedOperationException( );     }


    /** Removes all entries from this collection. **/
    public void clear()
    {   throw new UnsupportedOperationException( );     }


    public class LinkedNodeCollectionIterator implements Iterator
    {
        private ListNode next;
        private ListNode lastReturned;

      // ListNodeCollectionIterator constructor

        /** Constructs an iterator through a LinkedNodeCollectionIterator. **/
        public LinkedNodeCollectionIterator()
        {   next = head; lastReturned = null;  }

      // observer methods implemented in LNC Implementation Mini-Lab #1

        /** Returns true if there are more elements in the collection. **/
        public boolean hasNext()
        {   throw new UnsupportedOperationException( );     }

        /** Returns the next element in the collection. **/
        public Object next()
        {   throw new UnsupportedOperationException( );     }

      // modifier methods implemented in LNC Implementation Programming Project

        /** Adds object between element that was last returned
         *  and next element.
         **/
        public void add(Object obj)
        { throw new UnsupportedOperationException( ); }


        /** Removes the last element that was returned. **/
        public void remove()
        {   throw new UnsupportedOperationException( );     }

    } // end of class LinkedNodeCollectionIterator


} // end of class LinkedNodeCollection





