KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > common > JacORBVersionComparator


1 package org.jacorb.test.common;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 2005 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301, USA.
22  */

23
24 import java.util.*;
25
26 /**
27  * A Comparator that compares JacORB versions. Note that the static array
28  * <code>versions</code> must be updated each time a new JacORB version
29  * is released.
30  *
31  * @author Andre Spiegel spiegel@gnu.org
32  * @version $Id: JacORBVersionComparator.java,v 1.2 2005/05/13 13:16:05 andre.spiegel Exp $
33  */

34 public class JacORBVersionComparator implements Comparator
35 {
36     /**
37      * Contains the released versions of JacORB in chronological order.
38      * "cvs" must always be the final element.
39      */

40     private static final String JavaDoc[] versions =
41     {
42         "1.3.30", "1.4.1", "2.0", "2.1", "2.2", "2.2.1", "cvs"
43     };
44     
45     public int compare (Object JavaDoc o1, Object JavaDoc o2)
46     {
47         if (o1 == null && o2 == null)
48         {
49             return 0;
50         }
51         else if (o1 == null)
52         {
53             // no version is earlier than any version
54
return -1;
55         }
56         else if (o2 == null)
57         {
58             // any version is later than no version
59
return 1;
60         }
61         else if (o1 instanceof String JavaDoc && o2 instanceof String JavaDoc)
62         {
63             String JavaDoc s1 = (String JavaDoc)o1;
64             String JavaDoc s2 = (String JavaDoc)o2;
65
66             int i1 = versions.length,
67                 i2 = versions.length;
68
69             for (int i=0; i<versions.length; i++)
70             {
71                 if (s1.equals(versions[i])) i1 = i;
72                 if (s2.equals(versions[i])) i2 = i;
73             }
74             
75             if (i1 < i2) return -1;
76             else if (i1 > i2) return +1;
77             else return 0;
78         }
79         else
80         {
81             throw new IllegalArgumentException JavaDoc();
82         }
83     }
84 }
85
Popular Tags