PageRenderTime 60ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/Classes/TVhtml.vb

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