@Override public Integer visitVersion(OrderableSlsVersion version) { // o1 is smaller if it satisfies the max constraint of o2 return o2.isSatisfiedBy(version) ? -1 : 1; }
@Override public final String toString() { return visit(new MaximumVersionVisitor<String>() { @Override public String visitVersion(OrderableSlsVersion version) { return version.toString(); } @Override public String visitMatcher(SlsVersionMatcher matcher) { return matcher.toString(); } }); }
@Override public Integer visitMatcher(SlsVersionMatcher thisMatcher) { return o2.visit(new MaximumVersionVisitor<Integer>() { @Override public Integer visitVersion(OrderableSlsVersion version) { // We're going for 'which is more restrictive as a max' // outcome of 0 means that version is accepted by matcher return thisMatcher.compare(version) >= 0 ? 1 : -1; } @Override public Integer visitMatcher(SlsVersionMatcher matcher) { return SlsVersionMatcher.MATCHER_COMPARATOR.compare(thisMatcher, matcher); } }); } });
@Override public Integer visitVersion(OrderableSlsVersion version) { // o1 is smaller if it satisfies the max constraint of o2 return o2.isSatisfiedBy(version) ? -1 : 1; }
@Override public final String toString() { return visit(new MaximumVersionVisitor<String>() { @Override public String visitVersion(OrderableSlsVersion version) { return version.toString(); } @Override public String visitMatcher(SlsVersionMatcher matcher) { return matcher.toString(); } }); }
private static boolean satisfiesMaxVersion(Optional<MaximumVersion> maximumVersion, OrderableSlsVersion version) { // If maximumVersion is 1.5.x we should still accept e.g. 1.3.0 so we use '>= 0' // (comparison result is from the point of view of the matcher) return maximumVersion.map(maxVer -> maxVer.isSatisfiedBy(version)).orElse(true); }
@Override public Integer visitMatcher(SlsVersionMatcher thisMatcher) { return o2.visit(new MaximumVersionVisitor<Integer>() { @Override public Integer visitVersion(OrderableSlsVersion version) { // We're going for 'which is more restrictive as a max' // outcome of 0 means that version is accepted by matcher return thisMatcher.compare(version) >= 0 ? 1 : -1; } @Override public Integer visitMatcher(SlsVersionMatcher matcher) { return SlsVersionMatcher.MATCHER_COMPARATOR.compare(thisMatcher, matcher); } }); } });
private static boolean satisfiesMaxVersion(Optional<MaximumVersion> maximumVersion, OrderableSlsVersion version) { // If maximumVersion is 1.5.x we should still accept e.g. 1.3.0 so we use '>= 0' // (comparison result is from the point of view of the matcher) return maximumVersion.map(maxVer -> maxVer.isSatisfiedBy(version)).orElse(true); }
/** * True if the {@link OrderableSlsVersion} is less than or equal to the maximum version encoded in this object. */ final boolean isSatisfiedBy(OrderableSlsVersion version) { return visit(new MaximumVersionVisitor<Boolean>() { @Override public Boolean visitVersion(OrderableSlsVersion thisVersion) { return VersionComparator.INSTANCE.compare(thisVersion, version) >= 0; } @Override public Boolean visitMatcher(SlsVersionMatcher matcher) { // We're going for 'which is more restrictive as a max' // outcome of '0' means that version is accepted by matcher (not that they're equal) return matcher.compare(version) >= 0; } }); }
/** * True if the {@link OrderableSlsVersion} is less than or equal to the maximum version encoded in this object. */ final boolean isSatisfiedBy(OrderableSlsVersion version) { return visit(new MaximumVersionVisitor<Boolean>() { @Override public Boolean visitVersion(OrderableSlsVersion thisVersion) { return VersionComparator.INSTANCE.compare(thisVersion, version) >= 0; } @Override public Boolean visitMatcher(SlsVersionMatcher matcher) { // We're going for 'which is more restrictive as a max' // outcome of '0' means that version is accepted by matcher (not that they're equal) return matcher.compare(version) >= 0; } }); }
@Override public int compare(MaximumVersion o1, MaximumVersion o2) { return o1.visit(new MaximumVersionVisitor<Integer>() { @Override public Integer visitVersion(OrderableSlsVersion version) { // o1 is smaller if it satisfies the max constraint of o2 return o2.isSatisfiedBy(version) ? -1 : 1; } @Override public Integer visitMatcher(SlsVersionMatcher thisMatcher) { return o2.visit(new MaximumVersionVisitor<Integer>() { @Override public Integer visitVersion(OrderableSlsVersion version) { // We're going for 'which is more restrictive as a max' // outcome of 0 means that version is accepted by matcher return thisMatcher.compare(version) >= 0 ? 1 : -1; } @Override public Integer visitMatcher(SlsVersionMatcher matcher) { return SlsVersionMatcher.MATCHER_COMPARATOR.compare(thisMatcher, matcher); } }); } }); } }
@Override public int compare(MaximumVersion o1, MaximumVersion o2) { return o1.visit(new MaximumVersionVisitor<Integer>() { @Override public Integer visitVersion(OrderableSlsVersion version) { // o1 is smaller if it satisfies the max constraint of o2 return o2.isSatisfiedBy(version) ? -1 : 1; } @Override public Integer visitMatcher(SlsVersionMatcher thisMatcher) { return o2.visit(new MaximumVersionVisitor<Integer>() { @Override public Integer visitVersion(OrderableSlsVersion version) { // We're going for 'which is more restrictive as a max' // outcome of 0 means that version is accepted by matcher return thisMatcher.compare(version) >= 0 ? 1 : -1; } @Override public Integer visitMatcher(SlsVersionMatcher matcher) { return SlsVersionMatcher.MATCHER_COMPARATOR.compare(thisMatcher, matcher); } }); } }); } }