Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: lib/src/version_constraint.dart

Issue 2035983002: Make VersionRange implement Comparable. (Closed) Base URL: git@github.com:dart-lang/pub_semver@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'patterns.dart'; 5 import 'patterns.dart';
6 import 'version.dart'; 6 import 'version.dart';
7 import 'version_range.dart'; 7 import 'version_range.dart';
8 import 'version_union.dart'; 8 import 'version_union.dart';
9 import 'utils.dart'; 9 import 'utils.dart';
10 10
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } 187 }
188 188
189 // Only allow Versions and VersionRanges here so we can more easily reason 189 // Only allow Versions and VersionRanges here so we can more easily reason
190 // about everything in [flattened]. _EmptyVersions and VersionUnions are 190 // about everything in [flattened]. _EmptyVersions and VersionUnions are
191 // filtered out above. 191 // filtered out above.
192 for (var constraint in flattened) { 192 for (var constraint in flattened) {
193 if (constraint is VersionRange) continue; 193 if (constraint is VersionRange) continue;
194 throw new ArgumentError('Unknown VersionConstraint type $constraint.'); 194 throw new ArgumentError('Unknown VersionConstraint type $constraint.');
195 } 195 }
196 196
197 flattened.sort(compareMax); 197 flattened.sort();
198 198
199 var merged = <VersionRange>[]; 199 var merged = <VersionRange>[];
200 for (var constraint in flattened) { 200 for (var constraint in flattened) {
201 // Merge this constraint with the previous one, but only if they touch. 201 // Merge this constraint with the previous one, but only if they touch.
202 if (merged.isEmpty || 202 if (merged.isEmpty ||
203 (!merged.last.allowsAny(constraint) && 203 (!merged.last.allowsAny(constraint) &&
204 !areAdjacent(merged.last, constraint))) { 204 !areAdjacent(merged.last, constraint))) {
205 merged.add(constraint); 205 merged.add(constraint);
206 } else { 206 } else {
207 merged[merged.length - 1] = merged.last.union(constraint); 207 merged[merged.length - 1] = merged.last.union(constraint);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 String toString() => '<empty>'; 251 String toString() => '<empty>';
252 } 252 }
253 253
254 class _CompatibleWithVersionRange extends VersionRange { 254 class _CompatibleWithVersionRange extends VersionRange {
255 _CompatibleWithVersionRange(Version version) : super( 255 _CompatibleWithVersionRange(Version version) : super(
256 min: version, includeMin: true, 256 min: version, includeMin: true,
257 max: version.nextBreaking, includeMax: false); 257 max: version.nextBreaking, includeMax: false);
258 258
259 String toString() => '^$min'; 259 String toString() => '^$min';
260 } 260 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698