1 | #Region "Microsoft.VisualBasic::cad912ae1140ccfb151d96a22f387105, Microsoft.VisualBasic.Core\ComponentModel\Ranges\Selector\IntTag.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 | ' Structure IntTag |
35 | ' |
36 | ' Constructor: (+2 Overloads) Sub New |
37 | ' Function: CompareTo, OrderSelector, ToString |
38 | ' |
39 | ' |
40 | ' /********************************************************************************/ |
41 | |
42 | #End Region |
43 | |
44 | Imports Microsoft.VisualBasic.Serialization.JSON |
45 | |
46 | Namespace ComponentModel.Ranges |
47 | |
48 | Public Structure IntTag(Of T) |
49 | Implements IComparable |
50 | |
51 | Public ReadOnly n As Integer |
52 | Public ReadOnly x As T |
53 | |
54 | Sub New(x As T, getInt As Func(Of T, Integer)) |
55 | Me.x = x |
56 | Me.n = getInt(x) |
57 | End Sub |
58 | |
59 | Sub New(n As Integer) |
60 | Me.n = n |
61 | End Sub |
62 | |
63 | Public Overrides Function ToString() As String |
64 | Return Me.GetJson |
65 | End Function |
66 | |
67 | Public Function CompareTo(obj As Object) As Integer Implements IComparable.CompareTo |
68 | If obj Is Nothing Then |
69 | Return 1 |
70 | Else |
71 | If TypeOf obj Is Integer Then |
72 | Return n.CompareTo(DirectCast(obj, Integer)) |
73 | ElseIf TypeOf obj Is IntTag(Of T) Then |
74 | Return n.CompareTo(DirectCast(obj, IntTag(Of T)).n) |
75 | Else |
76 | Return 0 |
77 | End If |
78 | End If |
79 | End Function |
80 | |
81 | Public Shared Function OrderSelector(source As IEnumerable(Of T), |
82 | getInt As Func(Of T, Integer), |
83 | Optional asc As Boolean = True) As OrderSelector(Of IntTag(Of T)) |
84 | Dim array As IEnumerable(Of IntTag(Of T)) = source.Select(Function(x) New IntTag(Of T)(x, getInt)) |
85 | Dim selects As New OrderSelector(Of IntTag(Of T))(array, asc) |
86 | Return selects |
87 | End Function |
88 | |
89 | Public Shared Widening Operator CType(n As Integer) As IntTag(Of T) |
90 | Return New IntTag(Of T)(n) |
91 | End Operator |
92 | End Structure |
93 | End Namespace |