Option Strict On
Option Explicit On

Namespace Nexamas.UI.Virtualization

    ''' <summary>
    ''' Inclusive realized index range. The range is a fact produced by the virtualization engine; it does not create controls,
    ''' mutate items, or own selection state.
    ''' </summary>
    Friend NotInheritable Class MASVirtualizationRange

        Private Shared ReadOnly EmptyRange As MASVirtualizationRange = New MASVirtualizationRange(0, -1)

        Friend Shared ReadOnly Property Empty As MASVirtualizationRange
            Get
                Return EmptyRange
            End Get
        End Property

        Friend Sub New(firstIndex As Integer, lastIndex As Integer)
            Me.FirstIndex = firstIndex
            Me.LastIndex = lastIndex
        End Sub

        Friend ReadOnly Property FirstIndex As Integer
        Friend ReadOnly Property LastIndex As Integer

        Friend ReadOnly Property IsEmpty As Boolean
            Get
                Return LastIndex < FirstIndex
            End Get
        End Property

        Friend ReadOnly Property Count As Integer
            Get
                If IsEmpty Then
                    Return 0
                End If

                Return LastIndex - FirstIndex + 1
            End Get
        End Property

        Friend Function Contains(index As Integer) As Boolean
            Return Not IsEmpty AndAlso index >= FirstIndex AndAlso index <= LastIndex
        End Function

        Public Overrides Function ToString() As String
            If IsEmpty Then
                Return "Empty"
            End If

            Return FirstIndex.ToString(Globalization.CultureInfo.InvariantCulture) & ".." & LastIndex.ToString(Globalization.CultureInfo.InvariantCulture)
        End Function

    End Class

End Namespace
