package innerclasses;

import java.util.Iterator;
import java.util.NoSuchElementException;

/** Simple three-dimensional vector that is iterable over the dimensions. 
 *
 * @author Jerod Weinman
 */
public class Vector3D<AnyType> implements Iterable<AnyType> {

  private AnyType i,j,k; // Three components of the vector

  /** Construct a vector of the three specified components 
   *
   * @param i first component of the vector
   * @param j second component of the vector
   * @param k third component of the vector
   */
  public Vector3D(AnyType i, AnyType j, AnyType k) {
    this.i = i;
    this.j = j;
    this.k = k;
  }

  /**
   * Return an iterator over the components of this vector.
   *
   * @return iterator over the components of this vector
   */
  public Iterator<AnyType> iterator() { return new VectorIterator<AnyType>(); }

  /**
   * Iterator over the components of this vector.
   */
  private class VectorIterator<AnyType> implements Iterator<AnyType> {

    private int currentComponent = 0; 

    /** Determine whether there are more elements in this iterator.
     *
     * @return true if there are more elements 
     */
    public boolean hasNext() 
    { 
      return false; // YOUR CODE HERE
      
    }

    /** 
     * Return the next element of the vector.
     * 
     * @return the next element of the vector 
     * @throws NoSuchElementException when {@link hasNext} is <code>false</code>
     */
    public AnyType next() 
    { 
      return Vector3D.this.k; // Return an arbitrary component
    }

    /** 
     * Unsupported operation to remove an item from a vector of a
     * fixed-dimension. 
     *
     * @throws UnsupportedOperationException in any case
     */
    public void remove() { throw new UnsupportedOperationException (); }

  } /* VectorIterator */

  /** Driver program for the vector and its iterator */
  public static void main(String args[]) {

    // Create a vector of powers of two
    Vector3D<Integer> vec = new Vector3D<Integer>(4,8,16);

    // Get the iterator
    Iterator<Integer> iter = vec.iterator();

    for (int component : vec) // Iterate and print the components
      System.out.println(component);
    
  }
}
