import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import java.util.NoSuchElementException;

public class Library
{
  private Map items;

  public Library()
  { items = new HashMap();
  }

  public void add(LibraryItem theItem)
  { items.put(theItem.id(), theItem);
  }

  public void checkout(String id, String holder)
  { if(!items.containsKey(id))
    { throw new NoSuchElementException("id not in library");
    }
    else
    { LibraryItem it = (LibraryItem)items.get(id);
      if(it.holder() == null)
        it.setHolder(holder);
    }
  }

  public String getHolder(String id)
  { if(!items.containsKey(id))
    { throw new NoSuchElementException("id not in library");
    }
    else
    { LibraryItem it = (LibraryItem)items.get(id);
      return it.holder();
    }
  }

  // added for display purposes
  public void listItems()
  {
    Iterator itr = items.keySet().iterator();

    while(itr.hasNext())
      System.out.println(items.get(itr.next()));
  }
}



