1- using System ;
21using System . Collections . Generic ;
32using System . ComponentModel . DataAnnotations ;
43using System . Linq ;
@@ -83,83 +82,5 @@ public static IEnumerable<TermPart> Sort(IEnumerable<TermPart> terms)
8382 {
8483 return terms . OrderBy ( term => term . FullWeight ) ;
8584 }
86-
87- [ Obsolete ]
88- public static IEnumerable < TermPart > SortObsolete ( IEnumerable < TermPart > terms )
89- {
90- var list = terms . ToList ( ) ;
91- var index = list . ToDictionary ( x => x . FullPath ) ;
92- return list . OrderBy ( x => x , new TermsComparer ( index ) ) ;
93- }
94-
95- [ Obsolete ]
96- private class TermsComparer : IComparer < TermPart >
97- {
98- private readonly IDictionary < string , TermPart > _index ;
99-
100- public TermsComparer ( IDictionary < string , TermPart > index )
101- {
102- _index = index ;
103- }
104-
105- public int Compare ( TermPart x , TermPart y )
106- {
107-
108- // if two nodes have the same parent, then compare by weight, then by path
109- // /1/2/3 vs /1/2/4 => 3 vs 4
110- if ( x . Path == y . Path )
111- {
112- var weight = y . Weight . CompareTo ( x . Weight ) ;
113-
114- if ( weight != 0 )
115- {
116- return weight ;
117- }
118-
119- // if same parent path and same weight, compare by name
120- return string . Compare ( x . Name , y . Name , StringComparison . OrdinalIgnoreCase ) ;
121- }
122-
123- // if two nodes have different parents
124-
125- // if the two nodes have the same root, the deeper is after (i.e. one starts with the other)
126- // /1/2 vs /1/2/3 => /1/2 first
127-
128- if ( x . FullPath . StartsWith ( y . FullPath , StringComparison . OrdinalIgnoreCase ) )
129- {
130- return 1 ;
131- }
132-
133- if ( y . FullPath . StartsWith ( x . FullPath , StringComparison . OrdinalIgnoreCase ) )
134- {
135- return - 1 ;
136- }
137-
138- // otherwise compare first none matching parent
139- // /1/2 vs /1/3 => 2 vs 3
140- // /2/3 vs /4 => 2 vs 4
141-
142- var xPath = x . FullPath . Split ( new [ ] { '/' } , StringSplitOptions . RemoveEmptyEntries ) ;
143- var yPath = y . FullPath . Split ( new [ ] { '/' } , StringSplitOptions . RemoveEmptyEntries ) ;
144-
145- string xFullPath = "" , yFullPath = "" ;
146-
147- for ( var i = 0 ; i < Math . Min ( xPath . Length , yPath . Length ) ; i ++ )
148- {
149- xFullPath += "/" + xPath [ i ] ;
150- yFullPath += "/" + yPath [ i ] ;
151-
152- if ( ! xFullPath . Equals ( yFullPath , StringComparison . OrdinalIgnoreCase ) )
153- {
154- var xParent = _index [ xFullPath ] ;
155- var yParent = _index [ yFullPath ] ;
156-
157- return Compare ( xParent , yParent ) ;
158- }
159- }
160-
161- return 0 ;
162- }
163- }
16485 }
165- }
86+ }
0 commit comments