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

Unified Diff: lib/src/utils.dart

Issue 2035983002: Make VersionRange implement Comparable. (Closed) Base URL: git@github.com:dart-lang/pub_semver@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « CHANGELOG.md ('k') | lib/src/version.dart » ('j') | lib/src/version.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/utils.dart
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index 74d015ac1fb56bc9be15582d913da901cb29c285..6493ddac51caa46fcb96e1aa45cc88dfe29810ad 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -15,10 +15,15 @@ bool areAdjacent(VersionRange range1, VersionRange range2) {
/// A [Comparator] that compares the maximum versions of [range1] and [range2].
int compareMax(VersionRange range1, VersionRange range2) {
- if (range1.max < range2.max) return -1;
- if (range1.max > range2.max) return 1;
+ if (range1.max == null) {
+ if (range2.max == null) return 0;
+ return 1;
+ } else if (range2.max == null) {
+ return -1;
+ }
- if (!range1.includeMax && range2.includeMax) return -1;
- if (range1.includeMax && !range2.includeMax) return 1;
+ var result = range1.max.compareTo(range2.max);
+ if (result != 0) return result;
+ if (range1.includeMax != range2.includeMax) return range1.includeMax ? 1 : -1;
return 0;
}
« no previous file with comments | « CHANGELOG.md ('k') | lib/src/version.dart » ('j') | lib/src/version.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698