Option Strict On

Imports System
Imports System.Collections

Namespace Mbark.Sensors
    Public Class GuidAttemptDictionary
        Implements IDictionary
        Implements ICollection
        Implements IEnumerable
        Implements ICloneable
        Private mInnerHash As Hashtable

#Region "Constructors"
        Public Sub New()
            mInnerHash = New Hashtable
        End Sub

        Public Sub New(ByVal original As GuidAttemptDictionary)
            If original Is Nothing Then Throw New ArgumentNullException("original")
            mInnerHash = New Hashtable(original.InnerHash)
        End Sub

        Public Sub New(ByVal dictionary As IDictionary)
            mInnerHash = New Hashtable(dictionary)
        End Sub

        Public Sub New(ByVal capacity As Integer)
            mInnerHash = New Hashtable(capacity)
        End Sub

        Public Sub New(ByVal dictionary As IDictionary, ByVal loadFactor As Single)
            mInnerHash = New Hashtable(dictionary, loadFactor)
        End Sub

        Public Sub New(ByVal codeProvider As IHashCodeProvider, ByVal comparer As IComparer)
            mInnerHash = New Hashtable(codeProvider, comparer)
        End Sub

        Public Sub New(ByVal capacity As Integer, ByVal loadFactor As Integer)
            mInnerHash = New Hashtable(capacity, loadFactor)
        End Sub

        Public Sub New(ByVal dictionary As IDictionary, ByVal codeProvider As IHashCodeProvider, ByVal comparer As IComparer)
            mInnerHash = New Hashtable(dictionary, codeProvider, comparer)
        End Sub

        Public Sub New(ByVal capacity As Integer, ByVal codeProvider As IHashCodeProvider, ByVal comparer As IComparer)
            mInnerHash = New Hashtable(capacity, codeProvider, comparer)
        End Sub

        Public Sub New(ByVal dictionary As IDictionary, ByVal loadFactor As Single, ByVal codeProvider As IHashCodeProvider, ByVal comparer As IComparer)
            mInnerHash = New Hashtable(dictionary, loadFactor, codeProvider, comparer)
        End Sub

        Public Sub New(ByVal capacity As Integer, ByVal loadFactor As Integer, ByVal codeProvider As IHashCodeProvider, ByVal comparer As IComparer)
            mInnerHash = New Hashtable(capacity, loadFactor, codeProvider, comparer)
        End Sub


#End Region

#Region "Implementation of IDictionary"

        Private Function PrivateGetEnumerator() As IDictionaryEnumerator
            Return New GuidAttemptDictionaryEnumerator(Me)
        End Function

        Public Function IDictionary_GetEnumerator() As IDictionaryEnumerator Implements IDictionary.GetEnumerator
            Return PrivateGetEnumerator()
        End Function

        Public Function GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
            Return PrivateGetEnumerator()
        End Function

        Public Sub Remove(ByVal key As Guid)
            mInnerHash.Remove(key)
        End Sub

        Public Sub Remove(ByVal key As Object) Implements IDictionary.Remove
            Remove(CType(key, Guid))
        End Sub

        Public Function Contains(ByVal key As Guid) As Boolean
            Return mInnerHash.Contains(key)

        End Function

        Public Function Contains(ByVal key As Object) As Boolean Implements IDictionary.Contains
            Return Contains(CType(key, Guid))
        End Function

        Public Sub Clear() Implements IDictionary.Clear
            mInnerHash.Clear()
        End Sub

        Public Sub Add(ByVal key As Guid, ByVal value As SensorTaskAttempt)
            mInnerHash.Add(key, value)
        End Sub

        Public Sub Add(ByVal key As Object, ByVal value As Object) Implements IDictionary.Add
            Add(CType(key, Guid), CType(value, SensorTaskAttempt))
        End Sub

        Public ReadOnly Property IsReadOnly() As Boolean Implements IDictionary.IsReadOnly
            Get
                Return mInnerHash.IsReadOnly
            End Get
        End Property

        Default Public Property Item(ByVal key As Guid) As SensorTaskAttempt
            Get
                Return CType(mInnerHash(key), SensorTaskAttempt)
            End Get
            Set(ByVal value As SensorTaskAttempt)
                mInnerHash(key) = value
            End Set
        End Property


        Default Public Property Item(ByVal key As Object) As Object Implements IDictionary.Item
            Get
                Return Item(CType(key, Guid))
            End Get
            Set(ByVal value As Object)
                Item(CType(key, Guid)) = CType(value, SensorTaskAttempt)
            End Set
        End Property

        Public ReadOnly Property Values() As System.Collections.ICollection Implements IDictionary.Values
            Get
                Return mInnerHash.Values
            End Get
        End Property

        Public ReadOnly Property Keys() As System.Collections.ICollection Implements IDictionary.Keys
            Get
                Return mInnerHash.Keys
            End Get
        End Property

        Public ReadOnly Property IsFixedSize() As Boolean Implements IDictionary.IsFixedSize
            Get
                Return mInnerHash.IsFixedSize
            End Get
        End Property

#End Region

#Region "Implementation of ICollection"

        Public Sub CopyTo(ByVal array As System.Array, ByVal index As Integer) Implements ICollection.CopyTo
            mInnerHash.CopyTo(array, index)
        End Sub


        Public ReadOnly Property IsSynchronized() As Boolean Implements System.Collections.ICollection.IsSynchronized
            Get
                Return mInnerHash.IsSynchronized
            End Get
        End Property

        Public ReadOnly Property Count() As Integer Implements System.Collections.ICollection.Count
            Get
                Return mInnerHash.Count
            End Get
        End Property

        Public ReadOnly Property SyncRoot() As Object Implements System.Collections.ICollection.SyncRoot
            Get
                Return mInnerHash.SyncRoot
            End Get
        End Property

#End Region

#Region "Implementation of ICloneable"

        Public Function Clone() As GuidAttemptDictionary
            Dim innerClone As GuidAttemptDictionary = New GuidAttemptDictionary
            innerClone.mInnerHash = CType(mInnerHash.Clone(), Hashtable)

            Return innerClone
        End Function

        Public Function ICloneable_Clone() As Object Implements ICloneable.Clone
            Return Clone()
        End Function
#End Region

#Region "HashTable Methods"
        Public Function ContainsKey(ByVal key As Guid) As Boolean
            Return mInnerHash.ContainsKey(key)
        End Function

        Public Function ContainsValue(ByVal value As SensorTaskAttempt) As Boolean
            Return mInnerHash.ContainsValue(value)
        End Function

        Public Shared Function Synchronized(ByVal nonSync As GuidAttemptDictionary) As GuidAttemptDictionary
            If nonSync Is Nothing Then Throw New ArgumentNullException("nonSync")
            Dim sync As GuidAttemptDictionary = New GuidAttemptDictionary
            sync.mInnerHash = Hashtable.Synchronized(nonSync.InnerHash)
            Return sync
        End Function
#End Region

        Friend ReadOnly Property InnerHash() As Hashtable
            Get
                Return mInnerHash
            End Get
        End Property
    End Class

    Public Class GuidAttemptDictionaryEnumerator
        Implements IDictionaryEnumerator

        Private innerEnumerator As IDictionaryEnumerator

        Friend Sub New(ByVal enumerable As GuidAttemptDictionary)
            innerEnumerator = enumerable.InnerHash.GetEnumerator()
        End Sub

#Region "Implementation of IDictionaryEnumerator"
        Public ReadOnly Property Key() As Guid
            Get
                Return CType(innerEnumerator.Key, Guid)
            End Get
        End Property

        Public ReadOnly Property IDictionaryEnumerator_Key() As Object Implements IDictionaryEnumerator.Key
            Get
                Return Key
            End Get
        End Property

        Public ReadOnly Property Value() As SensorTaskAttempt
            Get
                Return CType(innerEnumerator.Value, SensorTaskAttempt)
            End Get
        End Property

        Public ReadOnly Property IDictionaryEnumerator_Value() As Object Implements IDictionaryEnumerator.Value
            Get
                Return Value
            End Get
        End Property

        Public ReadOnly Property Entry() As System.Collections.DictionaryEntry Implements IDictionaryEnumerator.Entry
            Get
                Return innerEnumerator.Entry
            End Get
        End Property
#End Region

#Region "Implementation of IEnumerator"
        Public Sub Reset() Implements IDictionaryEnumerator.Reset
            innerEnumerator.Reset()
        End Sub

        Public Function MoveNext() As Boolean Implements IDictionaryEnumerator.MoveNext
            Return innerEnumerator.MoveNext()
        End Function

        Public ReadOnly Property CurrentObject() As Object Implements IDictionaryEnumerator.Current
            Get
                Return innerEnumerator.Current
            End Get
        End Property

        Public ReadOnly Property Current() As System.Collections.DictionaryEntry
            Get
                Return DirectCast(innerEnumerator.Current, System.Collections.DictionaryEntry)
            End Get
        End Property
#End Region
    End Class
End Namespace
