Public Class CustomerCollection
    Inherits System.Collections.CollectionBase

    ' members...
    Private _emailHashtable As New Hashtable()


    ' Add - add a customer...
    Public Sub Add(ByVal newCustomer As Customer)
        Me.List.Add(newCustomer)

        ' add to the hashtable...
        Dim useEmail As String
        useEmail = newCustomer.Email.ToLower
        EmailHashtable.Add(useEmail, newCustomer)

    End Sub

    ' Remove - delete a customer...
    Public Sub Remove(ByVal removeCustomer As Customer)
        Me.List.Remove(removeCustomer)

        ' remove from the hashtable...
        Dim useEmail As String
        useEmail = removeCustomer.Email.ToLower()
        EmailHashtable.Remove(useEmail)


    End Sub

    ' Item - return a customer given an index...
    Default Public Property Item(ByVal index As Integer) As Customer
        Get
            Return Me.List.Item(index)
        End Get
        Set(ByVal Value As Customer)
            Me.List.Item(index) = Value
        End Set
    End Property

    ' EmailHashtable - return the e-mail hashtable...
    Public ReadOnly Property EmailHashtable() As Hashtable
        Get
            Return _emailHashtable
        End Get
    End Property


    Default Public ReadOnly Property Item(ByVal email As String) _
            As Customer
        Get

            ' use a lower case term...
            email = email.ToLower()
            Return EmailHashtable.Item(email)

        End Get
    End Property

    ' Clear - provide a new implementation of clear...
    Public Shadows Sub Clear()

        ' get collectionbase to clear...
        MyBase.Clear()

        ' clear our hashtable...
        EmailHashtable.Clear()

    End Sub

    ' RemoveAt - remove an item by index...
    Public Shadows Sub RemoveAt(ByVal index As Integer)
        Remove(Item(index))
    End Sub


End Class
