Imports System
Imports System.ComponentModel
Imports System.Collections

Public MustInherit Class SwimData
  Protected Swimmers As ArrayList
  Private index As Integer

  Public Sub New()
    MyBase.New()
    index = 0
  End Sub

  Public Sub New(ByVal Filename As String)
    MyBase.New()
    Dim fl As New vbFile(Filename)
    Dim sw As Swimmer
    Dim sname As String

    Swimmers = New ArrayList()
    fl.OpenForRead(Filename)

    sname = fl.readLine
    While sname.Length > 0
      If (sname.Length > 0) Then
        sw = New Swimmer(sname)
        Swimmers.Add(sw)
      End If
      sname = fl.readLine
    End While
    sort()
    index = 0
  End Sub

  Public Sub Clone(ByVal swd As SwimData)
    Dim swmrs As New ArrayList()
    Dim i As Integer
    'Skopiuj dane z jednej kolekcji
    'do drugiej
    For i = 0 To Swimmers.Count - 1
      swmrs.Add(Swimmers(i))
    Next i
    swd.setData(swmrs)

  End Sub
  '-----
  Public Sub setData(ByVal swcol As ArrayList)
    Swimmers = swcol
    MoveFirst()
  End Sub
  '-----
  Public MustOverride Sub sort()
  '-----
  Public Sub MoveFirst()
    index = -1
  End Sub
  '-----
  Public Function hasMoreElements() As Boolean
    Return (index < (Swimmers.Count - 1))
  End Function
  '-----
  Public Function getNextSwimmer() As Swimmer
    index = index + 1
    Return CType(Swimmers(index), Swimmer)
  End Function

End Class
