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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « CHANGELOG.md ('k') | lib/src/version.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 'version_range.dart'; 5 import 'version_range.dart';
6 6
7 /// Returns whether [range1] is immediately next to, but not overlapping, 7 /// Returns whether [range1] is immediately next to, but not overlapping,
8 /// [range2]. 8 /// [range2].
9 bool areAdjacent(VersionRange range1, VersionRange range2) { 9 bool areAdjacent(VersionRange range1, VersionRange range2) {
10 if (range1.max != range2.min) return false; 10 if (range1.max != range2.min) return false;
11 11
12 return (range1.includeMax && !range2.includeMin) || 12 return (range1.includeMax && !range2.includeMin) ||
13 (!range1.includeMax && range2.includeMin); 13 (!range1.includeMax && range2.includeMin);
14 } 14 }
15 15
16 /// A [Comparator] that compares the maximum versions of [range1] and [range2]. 16 /// Returns whether [range1] allows lower versions than [range2].
17 int compareMax(VersionRange range1, VersionRange range2) { 17 bool allowsLower(VersionRange range1, VersionRange range2) {
18 if (range1.max == null) { 18 if (range1.min == null) return range2.min != null;
19 if (range2.max == null) return 0; 19 if (range2.min == null) return false;
20 return 1;
21 } else if (range2.max == null) {
22 return -1;
23 }
24 20
25 var result = range1.max.compareTo(range2.max); 21 var comparison = range1.min.compareTo(range2.min);
26 if (result != 0) return result; 22 if (comparison == -1) return true;
27 if (range1.includeMax != range2.includeMax) return range1.includeMax ? 1 : -1; 23 if (comparison == 1) return false;
28 return 0; 24 return range1.includeMin && !range2.includeMin;
29 } 25 }
26
27 /// Returns whether [range1] allows higher versions than [range2].
28 bool allowsHigher(VersionRange range1, VersionRange range2) {
29 if (range1.max == null) return range2.max != null;
30 if (range2.max == null) return false;
31
32 var comparison = range1.max.compareTo(range2.max);
33 if (comparison == 1) return true;
34 if (comparison == -1) return false;
35 return range1.includeMax && !range2.includeMax;
36 }
37
38 /// Returns whether [range1] allows only versions lower than those allowed by
39 /// [range2].
40 bool strictlyLower(VersionRange range1, VersionRange range2) {
41 if (range1.max == null || range2.min == null) return false;
42
43 var comparison = range1.max.compareTo(range2.min);
44 if (comparison == -1) return true;
45 if (comparison == 1) return false;
46 return !range1.includeMax || !range2.includeMin;
47 }
48
49 /// Returns whether [range1] allows only versions higher than those allowed by
50 /// [range2].
51 bool strictlyHigher(VersionRange range1, VersionRange range2) {
52 if (range1.min == null || range2.max == null) return false;
53
54 var comparison = range1.min.compareTo(range2.max);
55 if (comparison == 1) return true;
56 if (comparison == -1) return false;
57 return !range1.includeMin || !range2.includeMax;
58 }
OLDNEW
« 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