artifact implements comparable

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163984 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-04-20 16:49:24 +00:00
parent ab2070d797
commit a40f1eff93
2 changed files with 41 additions and 0 deletions

View File

@ -28,6 +28,7 @@ import java.util.List;
* @todo do we really need an interface here?
*/
public interface Artifact
extends Comparable
{
// TODO: into scope handler
String SCOPE_COMPILE = "compile";

View File

@ -249,4 +249,44 @@ public class DefaultArtifact
this.baseVersion = baseVersion;
}
public int compareTo( Object o )
{
Artifact a = (Artifact) o;
int result = groupId.compareTo( a.getGroupId() );
if ( result == 0 )
{
result = artifactId.compareTo( a.getArtifactId() );
if ( result == 0 )
{
result = type.compareTo( a.getType() );
if ( result == 0 )
{
if ( classifier == null )
{
if ( a.getClassifier() != null )
{
result = 1;
}
}
else
{
if ( a.getClassifier() != null )
{
result = classifier.compareTo( a.getClassifier() );
}
else
{
result = -1;
}
}
if ( result == 0 )
{
result = version.compareTo( a.getVersion() );
}
}
}
}
return result;
}
}