Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Collections
- Imports System.Collections.ObjectModel
- Imports System.Collections.Specialized
- Public Class SortedCollection(Of TKey, TItem)
- Implements IEnumerable(Of TItem)
- #Region "Properties"
- Default Public ReadOnly Property Item(key As TKey) As TItem
- Get
- Dim index = Me.Keys.IndexOf(key)
- Return Me.Items(index)
- End Get
- End Property
- Private _Keys As List(Of TKey)
- Private ReadOnly Property Keys As List(Of TKey)
- Get
- If _Keys Is Nothing Then
- _Keys = New List(Of TKey)()
- End If
- Return _Keys
- End Get
- End Property
- Private _Items As List(Of TItem)
- Private ReadOnly Property Items As List(Of TItem)
- Get
- If _Items Is Nothing Then
- _Items = New List(Of TItem)()
- End If
- Return _Items
- End Get
- End Property
- Public ReadOnly Property Count As Integer
- Get
- Return Me.Items.Count
- End Get
- End Property
- #End Region
- #Region "Methods"
- Public Overridable Sub Add(key As TKey, item As TItem)
- Me.Keys.Add(key)
- Me.Keys.Sort()
- Dim index = Me.Keys.IndexOf(key)
- Me.Items.Insert(index, item)
- End Sub
- Public Overridable Sub Remove(key As TKey)
- Dim index = Me.Keys.IndexOf(key)
- Me.Items.RemoveAt(index)
- Me.Keys.RemoveAt(index)
- End Sub
- Public Overridable Sub Clear()
- Me.Items.Clear()
- Me.Keys.Clear()
- End Sub
- Private Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
- Return Me.GetEnumerator()
- End Function
- Public Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of TItem) Implements System.Collections.Generic.IEnumerable(Of TItem).GetEnumerator
- Return Me.Items.GetEnumerator()
- End Function
- Public Function IndexOfKey(key As TKey) As Integer
- Return Me.Keys.IndexOf(key)
- End Function
- #End Region
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement