1 #Region "Microsoft.VisualBasic::1b88a93da9e25559b0041d7b6f7e21fa, Microsoft.VisualBasic.Core\ComponentModel\Ranges\RangeModel\Range.vb"
2
3     ' Author:
4     
5     '       asuka (amethyst.asuka@gcmodeller.org)
6     '       xie (genetics@smrucc.org)
7     '       xieguigang (xie.guigang@live.com)
8     
9     ' Copyright (c) 2018 GPL3 Licensed
10     
11     
12     ' GNU GENERAL PUBLIC LICENSE (GPL3)
13     
14     
15     ' This program is free software: you can redistribute it and/or modify
16     ' it under the terms of the GNU General Public License as published by
17     ' the Free Software Foundation, either version 3 of the License, or
18     ' (at your option) any later version.
19     
20     ' This program is distributed in the hope that it will be useful,
21     ' but WITHOUT ANY WARRANTY; without even the implied warranty of
22     ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23     ' GNU General Public License for more details.
24     
25     ' You should have received a copy of the GNU General Public License
26     ' along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28
29
30     ' /********************************************************************************/
31
32     ' Summaries:
33
34     '     Class Range
35     
36     '         Properties: Max, Min
37     
38     '         Constructor: (+1 OverloadsSub New
39     '         Function: (+2 OverloadsIsInside, IsOverlapping, ToString
40     
41     '     Class RangeTagValue
42     
43     '         Properties: Value
44     
45     '         Constructor: (+2 OverloadsSub New
46     '         FunctionToString
47     
48     
49     ' /********************************************************************************/
50
51 #End Region
52
53 Imports Microsoft.VisualBasic.Serialization.JSON
54
55 Namespace ComponentModel.Ranges.Model
56
57     Public Class Range(Of T As IComparable)
58         Implements IRanges(Of T)
59
60         Public ReadOnly Property Min As T Implements IRanges(Of T).Min
61         Public ReadOnly Property Max As T Implements IRanges(Of T).Max
62
63         Sub New(min As T, max As T)
64             Me.Min = min
65             Me.Max = max
66         End Sub
67
68         Public Overrides Function ToString() As String
69             Return Me.GetJson
70         End Function
71
72         Public Function IsInside(x As T) As Boolean Implements IRanges(Of T).IsInside
73             Return (Language.GreaterThanOrEquals(x, Min) AndAlso Language.LessThanOrEquals(x, Max))
74         End Function
75
76         Public Function IsInside(range As IRanges(Of T)) As Boolean Implements IRanges(Of T).IsInside
77             Return ((IsInside(range.Min)) AndAlso (IsInside(range.Max)))
78         End Function
79
80         Public Function IsOverlapping(range As IRanges(Of T)) As Boolean Implements IRanges(Of T).IsOverlapping
81             Return ((IsInside(range.Min)) OrElse (IsInside(range.Max)))
82         End Function
83     End Class
84
85     Public Class RangeTagValue(Of T As IComparable, V) : Inherits Range(Of T)
86
87         Public Property Value As V
88
89         Sub New(min As T, max As T)
90             Call MyBase.New(min, max)
91         End Sub
92
93         Sub New(min As T, max As T, value As V)
94             MyBase.New(min, max)
95             Me.Value = value
96         End Sub
97
98         Public Overrides Function ToString() As String
99             Return Me.GetJson
100         End Function
101     End Class
102 End Namespace