KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > latest > LatestLexicographicStrategy


1 /*
2  * This file is subject to the license found in LICENCE.TXT in the root directory of the project.
3  *
4  * #SNAPSHOT#
5  */

6 package fr.jayasoft.ivy.latest;
7
8 import java.util.Comparator JavaDoc;
9
10 import fr.jayasoft.ivy.ArtifactInfo;
11
12
13 public class LatestLexicographicStrategy extends ComparatorLatestStrategy {
14     /**
15      * Compares two revisions.
16      * Revisions are compared lexicographically unless
17      * a 'latest' revision is found. If the latest revision found
18      * is an absolute latest (latest. like), then it is assumed to be the greater.
19      * If a partial latest is found, then it is assumed to be greater
20      * than any matching fixed revision.
21      */

22     private static Comparator JavaDoc COMPARATOR = new Comparator JavaDoc() {
23         public int compare(Object JavaDoc o1, Object JavaDoc o2) {
24             String JavaDoc rev1 = ((ArtifactInfo)o1).getRevision();
25             String JavaDoc rev2 = ((ArtifactInfo)o2).getRevision();
26             if (rev1.startsWith("latest")) {
27                 return 1;
28             }
29             if (rev1.endsWith("+") && rev2.startsWith(rev1.substring(0, rev1.length() - 1))) {
30                 return 1;
31             }
32             if (rev2.startsWith("latest")) {
33                 return -1;
34             }
35             if (rev2.endsWith("+") && rev1.startsWith(rev2.substring(0, rev2.length() - 1))) {
36                 return -1;
37             }
38             return rev1.compareTo(rev2);
39         }
40     
41     };
42     
43     public LatestLexicographicStrategy() {
44         super(COMPARATOR);
45         setName("latest-lexico");
46     }
47     
48 }
49
Popular Tags