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

Unified Diff: lib/src/utils.dart

Issue 2045803002: Add VersionConstraint.difference(). (Closed) Base URL: git@github.com:dart-lang/pub_semver@master
Patch Set: Code review changes 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « CHANGELOG.md ('k') | lib/src/version.dart » ('j') | no next file with comments »
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 6493ddac51caa46fcb96e1aa45cc88dfe29810ad..efe105abed966f9f65f77fdc2d1bd876a092d512 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -13,17 +13,46 @@ bool areAdjacent(VersionRange range1, VersionRange range2) {
(!range1.includeMax && range2.includeMin);
}
-/// A [Comparator] that compares the maximum versions of [range1] and [range2].
-int compareMax(VersionRange range1, VersionRange range2) {
- if (range1.max == null) {
- if (range2.max == null) return 0;
- return 1;
- } else if (range2.max == null) {
- 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;
+/// Returns whether [range1] allows lower versions than [range2].
+bool allowsLower(VersionRange range1, VersionRange range2) {
+ if (range1.min == null) return range2.min != null;
+ if (range2.min == null) return false;
+
+ var comparison = range1.min.compareTo(range2.min);
+ if (comparison == -1) return true;
+ if (comparison == 1) return false;
+ return range1.includeMin && !range2.includeMin;
+}
+
+/// Returns whether [range1] allows higher versions than [range2].
+bool allowsHigher(VersionRange range1, VersionRange range2) {
+ if (range1.max == null) return range2.max != null;
+ if (range2.max == null) return false;
+
+ var comparison = range1.max.compareTo(range2.max);
+ if (comparison == 1) return true;
+ if (comparison == -1) return false;
+ return range1.includeMax && !range2.includeMax;
+}
+
+/// Returns whether [range1] allows only versions lower than those allowed by
+/// [range2].
+bool strictlyLower(VersionRange range1, VersionRange range2) {
+ if (range1.max == null || range2.min == null) return false;
+
+ var comparison = range1.max.compareTo(range2.min);
+ if (comparison == -1) return true;
+ if (comparison == 1) return false;
+ return !range1.includeMax || !range2.includeMin;
+}
+
+/// Returns whether [range1] allows only versions higher than those allowed by
+/// [range2].
+bool strictlyHigher(VersionRange range1, VersionRange range2) {
+ if (range1.min == null || range2.max == null) return false;
+
+ var comparison = range1.min.compareTo(range2.max);
+ if (comparison == 1) return true;
+ if (comparison == -1) return false;
+ return !range1.includeMin || !range2.includeMax;
}
« no previous file with comments | « CHANGELOG.md ('k') | lib/src/version.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698