updated version comparison classes with modifications done earlier in maven-artifact

git-svn-id: https://svn.apache.org/repos/asf/maven/mercury/trunk@900175 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/mercury-core/src/main/java/org/apache/maven/mercury/artifact/version/ComparableVersion.java b/mercury-core/src/main/java/org/apache/maven/mercury/artifact/version/ComparableVersion.java
index 05e579a..10b59be 100644
--- a/mercury-core/src/main/java/org/apache/maven/mercury/artifact/version/ComparableVersion.java
+++ b/mercury-core/src/main/java/org/apache/maven/mercury/artifact/version/ComparableVersion.java
@@ -25,15 +25,35 @@
 import java.util.Properties;
 import java.util.Stack;
 
-/*
- * Generic implementation of version comparison.
+/**
+ * Generic implementation of version comparison. Features:
+ * <ul>
+ * <li>mixing of '<code>-</code>' (dash) and '<code>.</code>' (dot) separators,</li>
+ * <li>transition between characters and digits also constitutes a separator:
+ *     <code>1.0alpha1 =&gt; [1, 0, alpha, 1]</code></li>
+ * <li>unlimited number of version components,</li>
+ * <li>version components in the text can be digits or strings</li>
+ * <li>strings are checked for well-known qualifiers and the qualifier ordering is used for version ordering.
+ *     Well-known qualifiers (case insensitive):<ul>
+ *     <li><code>snapshot</code></li>
+ *     <li><code>alpha</code> or <code>a</code></li>
+ *     <li><code>beta</code> or <code>b</code></li>
+ *     <li><code>milestone</code> or <code>m</code></li>
+ *     <li><code>rc</code> or <code>cr</code></li>
+ *     <li><code>(the empty string)</code> or <code>ga</code> or <code>final</code></li>
+ *     <li><code>sp</code></li>
+ *     </ul>
+ *   </li>
+ * <li>a dash usually precedes a qualifier, and is always less important than something preceded with a dot.</li>
+ * </ul>
  *
+ * @see <a href="http://docs.codehaus.org/display/MAVEN/Versioning">"Versioning" on Maven Wiki</a>
  * @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
- * @author <a href="mailto:hboutemy@apache.org">Herve Boutemy</a>
+ * @author <a href="mailto:hboutemy@apache.org">Hervé Boutemy</a>
  * @version $Id$
  */
 public class ComparableVersion
-    implements Comparable
+    implements Comparable<ComparableVersion>
 {
     private String value;
 
@@ -125,7 +145,7 @@
     {
         private final static String[] QUALIFIERS = { "alpha", "beta", "milestone", "rc", "snapshot", "", "sp" };
 
-        private final static List _QUALIFIERS = Arrays.asList( QUALIFIERS );
+        private final static List<String> _QUALIFIERS = Arrays.asList( QUALIFIERS );
 
         private final static Properties ALIASES = new Properties();
         static
@@ -139,7 +159,7 @@
          * A comparable for the empty-string qualifier. This one is used to determine if a given qualifier makes the
          * version older than one without a qualifier, or more recent.
          */
-        private static Comparable RELEASE_VERSION_INDEX = String.valueOf( _QUALIFIERS.indexOf( "" ) );
+        private static String RELEASE_VERSION_INDEX = String.valueOf( _QUALIFIERS.indexOf( "" ) );
 
         private String value;
 
@@ -175,16 +195,19 @@
         }
 
         /**
-         * Returns a comparable for a qualifier. This method both takes into account the ordering of known qualifiers as
-         * well as lexical ordering for unknown qualifiers. just returning an Integer with the index here is faster, but
-         * requires a lot of if/then/else to check for -1 or QUALIFIERS.size and then resort to lexical ordering. Most
-         * comparisons are decided by the first character, so this is still fast. If more characters are needed then it
-         * requires a lexical sort anyway.
+         * Returns a comparable value for a qualifier.
+         *
+         * This method both takes into account the ordering of known qualifiers as well as lexical ordering for unknown
+         * qualifiers.
+         *
+         * just returning an Integer with the index here is faster, but requires a lot of if/then/else to check for -1
+         * or QUALIFIERS.size and then resort to lexical ordering. Most comparisons are decided by the first character,
+         * so this is still fast. If more characters are needed then it requires a lexical sort anyway.
          *
          * @param qualifier
-         * @return
+         * @return an equivalent value that can be used with lexical comparison
          */
-        public static Comparable comparableQualifier( String qualifier )
+        public static String comparableQualifier( String qualifier )
         {
             int i = _QUALIFIERS.indexOf( qualifier );
 
@@ -225,7 +248,7 @@
      * with '-(number)' in the version specification).
      */
     private static class ListItem
-        extends ArrayList
+        extends ArrayList<Item>
         implements Item
     {
         public int getType()
@@ -240,9 +263,9 @@
 
         void normalize()
         {
-            for ( ListIterator iterator = listIterator( size() ); iterator.hasPrevious(); )
+            for ( ListIterator<Item> iterator = listIterator( size() ); iterator.hasPrevious(); )
             {
-                Item item = (Item) iterator.previous();
+                Item item = iterator.previous();
                 if ( item.isNull() )
                 {
                     iterator.remove(); // remove null trailing items: 0, "", empty list
@@ -275,8 +298,8 @@
                     return 1; // 1-1 > 1-sp
 
                 case LIST_ITEM:
-                    Iterator left = iterator();
-                    Iterator right = ( (ListItem) item ).iterator();
+                    Iterator<Item> left = iterator();
+                    Iterator<Item> right = ( (ListItem) item ).iterator();
 
                     while ( left.hasNext() || right.hasNext() )
                     {
@@ -302,7 +325,7 @@
         public String toString()
         {
             StringBuffer buffer = new StringBuffer( "(" );
-            for ( Iterator iter = iterator(); iter.hasNext(); )
+            for ( Iterator<Item> iter = iterator(); iter.hasNext(); )
             {
                 buffer.append( iter.next() );
                 if ( iter.hasNext() )
@@ -330,7 +353,7 @@
 
         ListItem list = items;
 
-        Stack stack = new Stack();
+        Stack<Item> stack = new Stack<Item>();
         stack.push( list );
 
         boolean isDigit = false;
@@ -420,9 +443,9 @@
         return isDigit ? new IntegerItem( buf ) : new StringItem( buf, false );
     }
 
-    public int compareTo( Object o )
+    public int compareTo( ComparableVersion o )
     {
-        return items.compareTo( ( (ComparableVersion) o ).items );
+        return items.compareTo( o.items );
     }
 
     public String toString()
diff --git a/mercury-core/src/test/java/org/apache/maven/mercury/artifact/version/ComparableVersionTest.java b/mercury-core/src/test/java/org/apache/maven/mercury/artifact/version/ComparableVersionTest.java
index 1480afb..da9f29a 100644
--- a/mercury-core/src/test/java/org/apache/maven/mercury/artifact/version/ComparableVersionTest.java
+++ b/mercury-core/src/test/java/org/apache/maven/mercury/artifact/version/ComparableVersionTest.java
@@ -29,6 +29,7 @@
  * @author <a href="mailto:hboutemy@apache.org">Herve Boutemy</a>
  * @version $Id$
  */
+@SuppressWarnings( "unchecked" )
 public class ComparableVersionTest
     extends TestCase
 {
@@ -104,12 +105,19 @@
         checkVersionsEqual( "1", "1-0" );
         checkVersionsEqual( "1", "1.0-0" );
         checkVersionsEqual( "1.0", "1.0-0" );
+        // no separator between number and character
         checkVersionsEqual( "1a", "1.a" );
         checkVersionsEqual( "1a", "1-a" );
         checkVersionsEqual( "1a", "1.0-a" );
         checkVersionsEqual( "1a", "1.0.0-a" );
         checkVersionsEqual( "1.0a", "1.0.a" );
         checkVersionsEqual( "1.0.0a", "1.0.0.a" );
+        checkVersionsEqual( "1x", "1.x" );
+        checkVersionsEqual( "1x", "1-x" );
+        checkVersionsEqual( "1x", "1.0-x" );
+        checkVersionsEqual( "1x", "1.0.0-x" );
+        checkVersionsEqual( "1.0x", "1.0.x" );
+        checkVersionsEqual( "1.0.0x", "1.0.0.x" );
 
         // aliases
         checkVersionsEqual( "1ga", "1" );
@@ -120,6 +128,22 @@
         checkVersionsEqual( "1a1", "1alpha1" );
         checkVersionsEqual( "1b2", "1beta2" );
         checkVersionsEqual( "1m3", "1milestone3" );
+
+        // case insensitive
+        checkVersionsEqual( "1X", "1x" );
+        checkVersionsEqual( "1A", "1a" );
+        checkVersionsEqual( "1B", "1b" );
+        checkVersionsEqual( "1M", "1m" );
+        checkVersionsEqual( "1Ga", "1" );
+        checkVersionsEqual( "1GA", "1" );
+        checkVersionsEqual( "1Final", "1" );
+        checkVersionsEqual( "1FinaL", "1" );
+        checkVersionsEqual( "1FINAL", "1" );
+        checkVersionsEqual( "1Cr", "1Rc" );
+        checkVersionsEqual( "1cR", "1rC" );
+        checkVersionsEqual( "1m3", "1Milestone3" );
+        checkVersionsEqual( "1m3", "1MileStone3" );
+        checkVersionsEqual( "1m3", "1MILESTONE3" );
     }
 
     public void testVersionComparing()