Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding some of the remaining AbstractVersionDetails methods to the interface #751

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ protected AbstractVersionDetails()
{
}

@Override
public final boolean isCurrentVersionDefined()
{
return getCurrentVersion() != null;
}

@Override
public final ArtifactVersion getCurrentVersion()
{
synchronized ( currentVersionLock )
Expand All @@ -88,6 +90,7 @@ public final ArtifactVersion getCurrentVersion()
}
}

@Override
public final void setCurrentVersion( ArtifactVersion currentVersion )
{
synchronized ( currentVersionLock )
Expand All @@ -96,11 +99,13 @@ public final void setCurrentVersion( ArtifactVersion currentVersion )
}
}

@Override
public final void setCurrentVersion( String currentVersion )
{
setCurrentVersion( currentVersion == null ? null : new DefaultArtifactVersion( currentVersion ) );
}

@Override
public final boolean isIncludeSnapshots()
{
synchronized ( currentVersionLock )
Expand All @@ -109,6 +114,7 @@ public final boolean isIncludeSnapshots()
}
}

@Override
public final void setIncludeSnapshots( boolean includeSnapshots )
{
synchronized ( currentVersionLock )
Expand All @@ -117,48 +123,50 @@ public final void setIncludeSnapshots( boolean includeSnapshots )
}
}

@Override
public final ArtifactVersion[] getVersions()
{
return getVersions( isIncludeSnapshots() );
}

@Override
public abstract ArtifactVersion[] getVersions( boolean includeSnapshots );

@Override
public final ArtifactVersion[] getVersions( VersionRange versionRange, boolean includeSnapshots )
{
return getVersions( versionRange, null, includeSnapshots );
}

@Override
public final ArtifactVersion[] getVersions( ArtifactVersion lowerBound, ArtifactVersion upperBound )
{
return getVersions( lowerBound, upperBound, isIncludeSnapshots() );
}

@Override
public final ArtifactVersion[] getVersions( ArtifactVersion lowerBound, ArtifactVersion upperBound,
boolean includeSnapshots )
{
Restriction restriction = new Restriction( lowerBound, false, upperBound, false );
return getVersions( restriction, includeSnapshots );
}

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

@Override
public final ArtifactVersion getNewestVersion( ArtifactVersion lowerBound, ArtifactVersion upperBound )
{
return getNewestVersion( lowerBound, upperBound, isIncludeSnapshots() );
}

@Override
public final ArtifactVersion getNewestVersion( ArtifactVersion lowerBound, ArtifactVersion upperBound,
boolean includeSnapshots )
{
Restriction restriction = new Restriction( lowerBound, false, upperBound, false );
return getNewestVersion( restriction, includeSnapshots );
}

@Override
public final ArtifactVersion getNewestVersion( VersionRange versionRange, Restriction restriction,
boolean includeSnapshots )
{
Expand All @@ -170,6 +178,7 @@ private static <T> Iterable<T> reverse( T[] array )
return Arrays.stream( array ).sorted( Collections.reverseOrder() ).collect( Collectors.toList() );
}

@Override
public final ArtifactVersion getNewestVersion( VersionRange versionRange, Restriction restriction,
boolean includeSnapshots, boolean allowDowngrade )
{
Expand All @@ -194,16 +203,19 @@ public final ArtifactVersion getNewestVersion( VersionRange versionRange, Restri
return null;
}

@Override
public final ArtifactVersion getNewestVersion( Restriction restriction, boolean includeSnapshots )
{
return getNewestVersion( null, restriction, includeSnapshots );
}

@Override
public final ArtifactVersion getNewestVersion( VersionRange versionRange, boolean includeSnapshots )
{
return getNewestVersion( versionRange, null, includeSnapshots );
}

@Override
public final boolean containsVersion( String version )
{
for ( ArtifactVersion candidate : getVersions( true ) )
Expand All @@ -216,45 +228,28 @@ public final boolean containsVersion( String version )
return false;
}

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

@Override
public final ArtifactVersion[] getNewerVersions( String version, boolean includeSnapshots )
{
return getNewerVersions( new DefaultArtifactVersion( version ), includeSnapshots );
}

/**
* Returns an array of newer versions than the given version, given the upper bound segment and whether snapshots
* should be included.
*
* @param version current version
* @param upperBoundSegment the upper bound segment; empty() means no upper bound
* @param includeSnapshots whether snapshot versions should be included
* @return array of newer versions fulfilling the criteria
* @throws InvalidSegmentException if the requested segment is outside the bounds (less than 1 or greater than
* the segment count)
* @deprecated please use {@link AbstractVersionDetails#getNewerVersions(String, Optional, boolean, boolean)},
* boolean, boolean)} instead
*/
@Deprecated
@Override
public final ArtifactVersion[] getNewerVersions( String version, Optional<Segment> upperBoundSegment,
boolean includeSnapshots )
throws InvalidSegmentException
{
return getNewerVersions( version, upperBoundSegment, includeSnapshots, false );
}

/**
* Returns an array of newer versions than the given version, given the upper bound segment and whether snapshots
* should be included.
*
* @param versionString current version
* @param upperBoundSegment the upper bound segment; empty() means no upper bound
* @param includeSnapshots whether snapshot versions should be included
* @param allowDowngrade whether to allow downgrading if the current version is a snapshots and snapshots
* are disallowed
* @return array of newer versions fulfilling the criteria
* @throws InvalidSegmentException if the requested segment is outside the bounds (less than 1 or greater than
* the segment count)
*/
@Override
public final ArtifactVersion[] getNewerVersions( String versionString, Optional<Segment> upperBoundSegment,
boolean includeSnapshots, boolean allowDowngrade )
throws InvalidSegmentException
Expand All @@ -279,17 +274,20 @@ public final ArtifactVersion[] getNewerVersions( String versionString, Optional<
return getVersions( restriction, includeSnapshots );
}

@Override
public final ArtifactVersion getOldestVersion( VersionRange versionRange, boolean includeSnapshots )
{
return getOldestVersion( versionRange, null, includeSnapshots );
}

@Override
public final ArtifactVersion getOldestVersion( Restriction restriction,
boolean includeSnapshots )
{
return getOldestVersion( null, restriction, includeSnapshots );
}

@Override
public final ArtifactVersion getOldestVersion( VersionRange versionRange, Restriction restriction,
boolean includeSnapshots )
{
Expand Down Expand Up @@ -321,11 +319,13 @@ else if ( versionComparator.compare( oldest, candidate ) > 0 )
return oldest;
}

@Override
public final ArtifactVersion[] getVersions( Restriction restriction, boolean includeSnapshots )
{
return getVersions( null, restriction, includeSnapshots );
}

@Override
public final ArtifactVersion[] getVersions( VersionRange versionRange, Restriction restriction,
boolean includeSnapshots )
{
Expand All @@ -350,6 +350,7 @@ public final ArtifactVersion[] getVersions( VersionRange versionRange, Restricti
return result.toArray( new ArtifactVersion[0] );
}

@Override
public final ArtifactVersion getOldestUpdate( ArtifactVersion currentVersion, Optional<Segment> updateScope,
boolean includeSnapshots )
{
Expand All @@ -364,6 +365,7 @@ public final ArtifactVersion getOldestUpdate( ArtifactVersion currentVersion, Op
}
}

@Override
public final ArtifactVersion getNewestUpdate( ArtifactVersion currentVersion, Optional<Segment> updateScope,
boolean includeSnapshots )
{
Expand All @@ -378,6 +380,7 @@ public final ArtifactVersion getNewestUpdate( ArtifactVersion currentVersion, Op
}
}

@Override
public final ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, Optional<Segment> updateScope,
boolean includeSnapshots )
{
Expand All @@ -392,21 +395,25 @@ public final ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, Op
}
}

@Override
public final ArtifactVersion getOldestUpdate( Optional<Segment> updateScope )
{
return getOldestUpdate( updateScope, isIncludeSnapshots() );
}

@Override
public final ArtifactVersion getNewestUpdate( Optional<Segment> updateScope )
{
return getNewestUpdate( updateScope, isIncludeSnapshots() );
}

@Override
public final ArtifactVersion[] getAllUpdates( Optional<Segment> updateScope )
{
return getAllUpdates( updateScope, isIncludeSnapshots() );
}

@Override
public final ArtifactVersion getOldestUpdate( Optional<Segment> updateScope, boolean includeSnapshots )
{
if ( isCurrentVersionDefined() )
Expand All @@ -416,6 +423,7 @@ public final ArtifactVersion getOldestUpdate( Optional<Segment> updateScope, boo
return null;
}

@Override
public final ArtifactVersion getNewestUpdate( Optional<Segment> updateScope, boolean includeSnapshots )
{
if ( isCurrentVersionDefined() )
Expand All @@ -425,6 +433,7 @@ public final ArtifactVersion getNewestUpdate( Optional<Segment> updateScope, boo
return null;
}

@Override
public final ArtifactVersion[] getAllUpdates( Optional<Segment> updateScope, boolean includeSnapshots )
{
if ( isCurrentVersionDefined() )
Expand All @@ -434,11 +443,13 @@ public final ArtifactVersion[] getAllUpdates( Optional<Segment> updateScope, boo
return null;
}

@Override
public final ArtifactVersion[] getAllUpdates( VersionRange versionRange )
{
return getAllUpdates( versionRange, isIncludeSnapshots() );
}

@Override
public ArtifactVersion[] getAllUpdates( VersionRange versionRange, boolean includeSnapshots )
{
Restriction restriction = new Restriction( getCurrentVersion(), false, null, false );
Expand Down
Loading