// A class that stores a collection of Shapes read 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 = Integer.parseInt(tLine);
            tLine = pInputHandle.readLine(); //BJCHEREFIRST
            final int tX = Integer.parseInt(tLine);
            tLine = pInputHandle.readLine();
            final int tY = Integer.parseInt(tLine);
            switch (tKey)
            {
               case 1:
               {
                  tLine = pInputHandle.readLine();
                  final int tRadius = Integer.parseInt(tLine);
                  final Circle tCircle = new Circle(tRadius, tX, tY);
                  iList.add(tCircle);
               }
               break;
               case 2:
               {
                  tLine = pInputHandle.readLine();
                  final int tWidth = Integer.parseInt(tLine);
                  tLine = pInputHandle.readLine();
                  final int tHeight = Integer.parseInt(tLine);
                  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);
   }
}
