microsoft-visualbasic-runtime/ComponentModel/Ranges/RangeModel/Range.vb

103 lines
3.2 KiB
VB.net
Raw Normal View History

2020-03-28 15:44:37 +08:00
#Region "Microsoft.VisualBasic::25f7439690cdf2cebb6257a221b2987f, Microsoft.VisualBasic.Core\ComponentModel\Ranges\RangeModel\Range.vb"
2018-08-02 20:14:48 +08:00
' Author:
'
' asuka (amethyst.asuka@gcmodeller.org)
' xie (genetics@smrucc.org)
' xieguigang (xie.guigang@live.com)
'
' Copyright (c) 2018 GPL3 Licensed
'
'
' GNU GENERAL PUBLIC LICENSE (GPL3)
'
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.
' /********************************************************************************/
' Summaries:
' Class Range
'
' Properties: Max, Min
'
' Constructor: (+1 Overloads) Sub New
' Function: (+2 Overloads) IsInside, IsOverlapping, ToString
'
' Class RangeTagValue
'
' Properties: Value
'
' Constructor: (+2 Overloads) Sub New
' Function: ToString
'
'
' /********************************************************************************/
#End Region
Imports Microsoft.VisualBasic.Serialization.JSON
Namespace ComponentModel.Ranges.Model
Public Class Range(Of T As IComparable)
2020-03-08 08:11:08 +08:00
Implements IRangeModel(Of T)
2018-08-02 20:14:48 +08:00
2020-03-08 08:11:08 +08:00
Public ReadOnly Property Min As T Implements IRangeModel(Of T).Min
Public ReadOnly Property Max As T Implements IRangeModel(Of T).Max
2018-08-02 20:14:48 +08:00
Sub New(min As T, max As T)
Me.Min = min
Me.Max = max
End Sub
Public Overrides Function ToString() As String
Return Me.GetJson
End Function
2020-03-08 08:11:08 +08:00
Public Function IsInside(x As T) As Boolean Implements IRangeModel(Of T).IsInside
2018-08-02 20:14:48 +08:00
Return (Language.GreaterThanOrEquals(x, Min) AndAlso Language.LessThanOrEquals(x, Max))
End Function
2020-03-08 08:11:08 +08:00
Public Function IsInside(range As IRangeModel(Of T)) As Boolean Implements IRangeModel(Of T).IsInside
2018-08-02 20:14:48 +08:00
Return ((IsInside(range.Min)) AndAlso (IsInside(range.Max)))
End Function
2020-03-08 08:11:08 +08:00
Public Function IsOverlapping(range As IRangeModel(Of T)) As Boolean Implements IRangeModel(Of T).IsOverlapping
2018-08-02 20:14:48 +08:00
Return ((IsInside(range.Min)) OrElse (IsInside(range.Max)))
End Function
End Class
Public Class RangeTagValue(Of T As IComparable, V) : Inherits Range(Of T)
Public Property Value As V
Sub New(min As T, max As T)
Call MyBase.New(min, max)
End Sub
Sub New(min As T, max As T, value As V)
MyBase.New(min, max)
Me.Value = value
End Sub
Public Overrides Function ToString() As String
Return Me.GetJson
End Function
End Class
End Namespace