PageRenderTime 17ms CodeModel.GetById 12ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/Classes/TVhtml.vb

#
Visual Basic | 30 lines | 26 code | 2 blank | 2 comment | 0 complexity | f8f5cda9224b01a66679125dd66bc230 MD5 | raw file
 1Imports System.Collections.Generic
 2
 3Public Class SeasonEpisodeComparer
 4    Implements IComparer(Of String)
 5    Private Shared Function ParseSeasonEpisode(ByVal item As String, ByVal type As Boolean) As Integer
 6        Dim hyphenIndex As Integer = item.IndexOf("-")
 7        ' Normally do some error checking in case hyphenIndex==-1
 8        Dim firstPart As String
 9        If type = True Then
10            firstPart = item.Substring(0, hyphenIndex)
11        Else
12            firstPart = item.Substring(hyphenIndex + 1)
13        End If
14        Return Integer.Parse(firstPart)
15    End Function
16
17    Public Function Compare(ByVal first As String, ByVal second As String) _
18                As Integer Implements IComparer(Of String).Compare
19        ' In real code you would probably add nullity checks
20        Dim firstSeason As Integer = ParseSeasonEpisode(first, True)
21        Dim secondSeason As Integer = ParseSeasonEpisode(second, True)
22        Dim sameSeason As Integer = firstSeason.CompareTo(secondSeason)
23        If sameSeason = 0 Then
24            Dim firstEpisode As Integer = ParseSeasonEpisode(first, False)
25            Dim secondEpisode As Integer = ParseSeasonEpisode(second, False)
26            sameSeason = firstEpisode.CompareTo(secondEpisode)
27        End If
28        Return sameSeason
29    End Function
30End Class