/**
 * A simple database that contains TwoPartNumber objects 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 TwoPartNumberDatabase
{
    private static final int    CAPACITY = 1000;    

    private int                 nextIndex;
    private String[]            names;
    private TwoPartNumber[]     values;


    /**
     * Default Constructor.
     */
    public TwoPartNumberDatabase()
    {
	names  = new String[CAPACITY];
	values = new TwoPartNumber[CAPACITY];

	nextIndex = 0;
    }

    /**
     * Add a TwoPartNumber to the database.  The number
     * can be referred to (i.e., indexed by) the given name.
     *
     * @param name   The name of the TwoPartNumber
     * @param value  The TwoPartNumber
     */
    public void add(String name, TwoPartNumber value)
    {
	if (nextIndex < (names.length)) 
        {
	    names[nextIndex]  = name;
	    values[nextIndex] = value;

	    nextIndex++;
	}
    }

    /**
     * Get the TwoPartNumber with the given name (or null if
     * no such name exists).
     *
     * @param name   The name of the TwoPartNumber
     * @return       The TwoPartNumber (or null)
     */
    public TwoPartNumber get(String name)
    {
        for (int i=0; i<nextIndex; i++)
        {
	    if (names[i].equals(name)) return values[i];
	}

	return null;
    }
}


