Skip to content

Commit

Permalink
Restriction as parameter to prevent more than 7 parameters in methods…
Browse files Browse the repository at this point in the history
… in the next PRs.
  • Loading branch information
sultan authored and slawekjaranowski committed Sep 16, 2022
1 parent 9ea2e83 commit 44b8e87
Showing 1 changed file with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public final ArtifactVersion[] getVersions( ArtifactVersion lowerBound, Artifact

private ArtifactVersion[] getNewerVersions( ArtifactVersion version, boolean includeSnapshots )
{
Restriction restriction = new Restriction( version, false, null, false );
Restriction restriction = new Restriction( version, false, null, false );
return getVersions( restriction, includeSnapshots );
}

Expand Down Expand Up @@ -187,7 +187,7 @@ public final ArtifactVersion getNewestVersion( VersionRange versionRange, Restri
{
continue;
}
if ( restriction != null && !restriction.containsVersion( candidate ) )
if ( restriction != null && !isVersionInRestriction( restriction, candidate ) )
{
continue;
}
Expand Down Expand Up @@ -307,7 +307,7 @@ public final ArtifactVersion getOldestVersion( VersionRange versionRange, Restri
{
continue;
}
if ( restriction != null && !restriction.containsVersion( candidate ) )
if ( restriction != null && !isVersionInRestriction( restriction, candidate ) )
{
continue;
}
Expand Down Expand Up @@ -343,7 +343,7 @@ public final ArtifactVersion[] getVersions( VersionRange versionRange, Restricti
{
continue;
}
if ( restriction != null && !restriction.containsVersion( candidate ) )
if ( restriction != null && !isVersionInRestriction( restriction, candidate ) )
{
continue;
}
Expand Down Expand Up @@ -568,4 +568,33 @@ protected Optional<String> getLowerBound( ArtifactVersion version, int unchanged
}
return of( newVersion.toString() );
}

/**
* Checks if the candidate version is in the range of the restriction.
* a custom comparator is/can be used to have milestones and rcs before final releases,
* which is not yet possible with {@link Restriction#containsVersion(ArtifactVersion)}.
* @param restriction the range to check against.
* @param candidate the version to check.
* @return true if the candidate version is within the range of the restriction parameter.
*/
private boolean isVersionInRestriction( Restriction restriction, ArtifactVersion candidate )
{
ArtifactVersion lowerBound = restriction.getLowerBound();
ArtifactVersion upperBound = restriction.getUpperBound();
boolean includeLower = restriction.isLowerBoundInclusive();
boolean includeUpper = restriction.isUpperBoundInclusive();
final VersionComparator versionComparator = getVersionComparator();
int lower = lowerBound == null ? -1 : versionComparator.compare( lowerBound, candidate );
int upper = upperBound == null ? +1 : versionComparator.compare( upperBound, candidate );
if ( lower > 0 || upper < 0 )
{
return false;
}
if ( ( !includeLower && lower == 0 ) || ( !includeUpper && upper == 0 ) )
{
return false;
}
return true;
}

}

0 comments on commit 44b8e87

Please sign in to comment.