Skip to content

Commit

Permalink
[MNG-6693] Save another few % on a very commonly used method
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jun 28, 2019
1 parent 093cd64 commit e472b79
Showing 1 changed file with 15 additions and 6 deletions.
Expand Up @@ -54,7 +54,7 @@ else if ( Artifact.VERSION_FILE_PATTERN.matcher( version ).matches() )

public static String toSnapshotVersion( String version )
{
Validate.notBlank( version, "version can neither be null, empty nor blank" );
notBlank( version, "version can neither be null, empty nor blank" );

int lastHyphen = version.lastIndexOf( '-' );
if ( lastHyphen > 0 )
Expand All @@ -79,8 +79,8 @@ public static String versionlessKey( Artifact artifact )

public static String versionlessKey( String groupId, String artifactId )
{
Validate.notBlank( groupId, "groupId can neither be null, empty nor blank" );
Validate.notBlank( artifactId, "artifactId can neither be null, empty nor blank" );
notBlank( groupId, "groupId can neither be null, empty nor blank" );
notBlank( artifactId, "artifactId can neither be null, empty nor blank" );

return groupId + ":" + artifactId;
}
Expand All @@ -92,13 +92,22 @@ public static String key( Artifact artifact )

public static String key( String groupId, String artifactId, String version )
{
Validate.notBlank( groupId, "groupId can neither be null, empty nor blank" );
Validate.notBlank( artifactId, "artifactId can neither be null, empty nor blank" );
Validate.notBlank( version, "version can neither be null, empty nor blank" );
notBlank( groupId, "groupId can neither be null, empty nor blank" );
notBlank( artifactId, "artifactId can neither be null, empty nor blank" );
notBlank( version, "version can neither be null, empty nor blank" );

return groupId + ":" + artifactId + ":" + version;
}

private static void notBlank( String str, String message )
{
int c = str != null ? str.charAt( 0 ) : 0;
if ( ( c < '0' || c > '9' ) && ( c < 'a' || c > 'z' ) )
{
Validate.notBlank( str, message );
}
}

public static Map<String, Artifact> artifactMapByVersionlessId( Collection<Artifact> artifacts )
{
Map<String, Artifact> artifactMap = new LinkedHashMap<>();
Expand Down

0 comments on commit e472b79

Please sign in to comment.