    Imports System
    Imports System.Collections

    Namespace ASPNET.StarterKit.TimeTracker.BusinessLogicLayer

        '*********************************************************************
        '
        ' CategoriesCollection Class
        '
        ' The CategoriesCollection Class inherits from ArrayList.  It has its own implemenation
        ' of Sort based on the sortable Category fields.
        '
        '*********************************************************************

        Public Class CategoriesCollection
            Inherits ArrayList

            Public Enum CategoryFields
                Abbreviation
                Duration
                InitValue
                Name
            End Enum 'CategoryFields

            Public Overloads Sub Sort(ByVal sortField As CategoryFields, ByVal isAscending As Boolean)
                Select Case sortField
                    Case CategoryFields.Name
                        MyBase.Sort(New NameComparer())
                    Case CategoryFields.Abbreviation
                        MyBase.Sort(New AbbreviationComparer())
                    Case CategoryFields.Duration
                        MyBase.Sort(New DurationComparer())
                End Select

                If Not isAscending Then
                    MyBase.Reverse()
                End If
            End Sub 'Sort

            Private NotInheritable Class NameComparer
                Implements IComparer

                Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare
                    Dim first As Category = CType(x, Category)
                    Dim second As Category = CType(y, Category)
                    Return first.Name.CompareTo(second.Name)
                End Function 'Compare
            End Class 'NameComparer

            Private NotInheritable Class AbbreviationComparer
                Implements IComparer

                Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare
                    Dim first As Category = CType(x, Category)
                    Dim second As Category = CType(y, Category)
                    Return first.Abbreviation.CompareTo(second.Abbreviation)
                End Function 'Compare
            End Class 'AbbreviationComparer

            Private NotInheritable Class DurationComparer
                Implements IComparer
                Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare
                    Dim first As Category = CType(x, Category)
                    Dim second As Category = CType(y, Category)
                    Return first.EstDuration.CompareTo(second.EstDuration)
                End Function 'Compare
            End Class 'DurationComparer
        End Class 'CategoriesCollection
    End Namespace 'ASPNET.StarterKit.TimeTracker.BusinessLogicLayer