OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library pub_semver.src.utils; | |
6 | |
7 import 'version.dart'; | |
8 import 'version_constraint.dart'; | |
9 import 'version_range.dart'; | |
10 | |
11 /// Returns whether [constraint1] is immediately next to, but not overlapping, | |
12 /// [constraint2]. | |
13 /// | |
14 /// This assumes both constraints are either a [VersionRange] or a [Version]. | |
15 bool areAdjacent(VersionConstraint constraint1, VersionConstraint constraint2) { | |
16 if (_max(constraint1) != _min(constraint2)) return false; | |
17 | |
18 var includeMax = _includeMax(constraint1); | |
19 var includeMin = _includeMin(constraint2); | |
20 return (includeMax && !includeMin) || (!includeMax && includeMin); | |
21 } | |
22 | |
23 /// A [Comparator] that compares the maximum versions of [constraint1] and | |
24 /// [constraint2]. | |
25 /// | |
26 /// This assumes both constraints are either a [VersionRange] or a [Version]. | |
27 int compareMax(VersionConstraint constraint1, VersionConstraint constraint2) { | |
28 var max1 = _max(constraint1); | |
29 var max2 = _max(constraint2); | |
30 if (max1 < max2) return -1; | |
31 if (max1 > max2) return 1; | |
32 | |
33 var includeMax1 = _includeMax(constraint1); | |
34 var includeMax2 = _includeMax(constraint2); | |
35 if (!includeMax1 && includeMax2) return -1; | |
36 if (includeMax1 && !includeMax2) return 1; | |
37 return 0; | |
38 } | |
39 | |
Bob Nystrom
2015/05/05 20:49:09
Instead of these functions, how about just making
nweiz
2015/05/05 22:52:33
Done.
| |
40 /// Returns the minimum version of [constraint], which may be a [VersionRange] | |
41 /// or a [Version]. | |
42 Version _min(VersionConstraint constraint) => | |
43 constraint is VersionRange ? constraint.min : (constraint as Version); | |
44 | |
45 /// Returns whether [constraint], which may be a [VersionRange] or a [Version], | |
46 /// includes its minimum value. | |
47 bool _includeMin(VersionConstraint constraint) => | |
Bob Nystrom
2015/05/05 20:49:09
How about "_includesMin"?
| |
48 constraint is VersionRange ? constraint.includeMin : true; | |
49 | |
50 /// Returns the maximum version of [constraint], which may be a [VersionRange] | |
51 /// or a [Version]. | |
52 Version _max(VersionConstraint constraint) => | |
53 constraint is VersionRange ? constraint.max : (constraint as Version); | |
54 | |
55 /// Returns whether [constraint], which may be a [VersionRange] or a [Version], | |
56 /// includes its maximum value. | |
57 bool _includeMax(VersionConstraint constraint) => | |
Bob Nystrom
2015/05/05 20:49:08
Ditto.
| |
58 constraint is VersionRange ? constraint.includeMax : true; | |
OLD | NEW |