/**
 * A simple database that contains lengths indexed by a name
 *
 * Note: This implementation uses arrays and, hence, has a 
 *       fixed capacity.
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0  
 */
   public class LengthDatabase
   {
      private int                 nextIndex;
      private String[]            names;
      private Length[]            values;
   
   
    /**
     * Default Constructor
     */
      public LengthDatabase()
      {
         names  = new String[1000];
         values = new Length[1000];
      
         nextIndex = 0;
      }
   
   
    /**
     * Add a Length to the database.  The Length
     * can be referred to (i.e., indexed by) the given name
     *
     * @param name   The name of the Length
     * @param value  The Length
     */
      public void add(String name, Length value)
      {
         if (nextIndex < (names.length)) {
         
            names[nextIndex]  = name;
            values[nextIndex] = value;
         
            nextIndex++;
         }
      }
   
   
    /**
     * Get the Length with the given name (or null if
     * no such name exists)
     *
     * @param name   The name of the Length
     * @return       The Length (or null)
     */
      public Length get(String name)
      {
         int              i;
         Length           value;
      
         value = null;
         i     = 0;
         while ((value == null) && (i < nextIndex)) 
         {
            if (names[i].equals(name)) value = values[i];
         
            i++;
         }
      
         return value;
      }
    
   }


