// A class that can store a collection of Shapes created from a BufferedReader.
// Barry Cornelius, 20 June 2000
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.List;
public class ShapesCollection
{
   private List iList;
   public ShapesCollection(final BufferedReader pInputHandle)
   {
      iList = new ArrayList();
      try
      {
         while (true)
         {
            String tLine = pInputHandle.readLine();
            if (tLine==null)
            {
               break;
            }
            final int tKey = new Integer(tLine).intValue();
            tLine = pInputHandle.readLine();
            final int tX = new Integer(tLine).intValue();
            tLine = pInputHandle.readLine();
            final int tY = new Integer(tLine).intValue();
            switch (tKey)
            {
               case 1:
               {
                  tLine = pInputHandle.readLine();
                  final int tRadius = new Integer(tLine).intValue();
                  final Circle tCircle = new Circle(tRadius, tX, tY);
                  iList.add(tCircle);
               }
               break;
               case 2:
               {
                  tLine = pInputHandle.readLine();
                  final int tWidth = new Integer(tLine).intValue();
                  tLine = pInputHandle.readLine();
                  final int tHeight = new Integer(tLine).intValue();
                  final Rectangle tRectangle =
                                         new Rectangle(tWidth, tHeight, tX, tY);
                  iList.add(tRectangle);
               }
               break;
               default:
               {
                  System.out.println("unknown value for the key: " + tKey);
               }
               break;
            }
         }
      }
      catch(final IOException pIOException)
      {
         System.out.println("ignoring an IOException");
      }
   }
   public int size()
   {
      return iList.size();
   }
   public Shape get(final int pShapeNumber)
   {
      return (Shape)iList.get(pShapeNumber);
   }
}
