| OLD | NEW |
| 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 'package:collection/collection.dart'; | 5 import 'package:collection/collection.dart'; |
| 6 | 6 |
| 7 import 'utils.dart'; | 7 import 'utils.dart'; |
| 8 import 'version.dart'; | 8 import 'version.dart'; |
| 9 import 'version_constraint.dart'; | 9 import 'version_constraint.dart'; |
| 10 import 'version_range.dart'; | 10 import 'version_range.dart'; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 } | 48 } |
| 49 | 49 |
| 50 // Only allow Versions and VersionRanges here so we can more easily reason | 50 // Only allow Versions and VersionRanges here so we can more easily reason |
| 51 // about everything in [flattened]. _EmptyVersions and VersionUnions are | 51 // about everything in [flattened]. _EmptyVersions and VersionUnions are |
| 52 // filtered out above. | 52 // filtered out above. |
| 53 for (var constraint in flattened) { | 53 for (var constraint in flattened) { |
| 54 if (constraint is VersionRange) continue; | 54 if (constraint is VersionRange) continue; |
| 55 throw new ArgumentError('Unknown VersionConstraint type $constraint.'); | 55 throw new ArgumentError('Unknown VersionConstraint type $constraint.'); |
| 56 } | 56 } |
| 57 | 57 |
| 58 (flattened as List).sort(compareMax); | 58 flattened.sort(compareMax); |
| 59 | 59 |
| 60 var merged = <VersionRange>[]; | 60 var merged = <VersionRange>[]; |
| 61 for (var constraint in flattened) { | 61 for (var constraint in flattened) { |
| 62 // Merge this constraint with the previous one, but only if they touch. | 62 // Merge this constraint with the previous one, but only if they touch. |
| 63 if (merged.isEmpty || | 63 if (merged.isEmpty || |
| 64 (!merged.last.allowsAny(constraint) && | 64 (!merged.last.allowsAny(constraint) && |
| 65 !areAdjacent(merged.last, constraint))) { | 65 !areAdjacent(merged.last, constraint))) { |
| 66 merged.add(constraint); | 66 merged.add(constraint); |
| 67 } else { | 67 } else { |
| 68 merged[merged.length - 1] = merged.last.union(constraint); | 68 merged[merged.length - 1] = merged.last.union(constraint); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 171 |
| 172 bool operator ==(other) { | 172 bool operator ==(other) { |
| 173 if (other is! VersionUnion) return false; | 173 if (other is! VersionUnion) return false; |
| 174 return const ListEquality().equals(constraints, other.constraints); | 174 return const ListEquality().equals(constraints, other.constraints); |
| 175 } | 175 } |
| 176 | 176 |
| 177 int get hashCode => const ListEquality().hash(constraints); | 177 int get hashCode => const ListEquality().hash(constraints); |
| 178 | 178 |
| 179 String toString() => constraints.join(" or "); | 179 String toString() => constraints.join(" or "); |
| 180 } | 180 } |
| OLD | NEW |