1 package org.jacorb.test.common; 2 3 23 24 import java.util.*; 25 26 34 public class JacORBVersionComparator implements Comparator 35 { 36 40 private static final String [] 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 o1, Object o2) 46 { 47 if (o1 == null && o2 == null) 48 { 49 return 0; 50 } 51 else if (o1 == null) 52 { 53 return -1; 55 } 56 else if (o2 == null) 57 { 58 return 1; 60 } 61 else if (o1 instanceof String && o2 instanceof String ) 62 { 63 String s1 = (String )o1; 64 String s2 = (String )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 (); 82 } 83 } 84 } 85 | Popular Tags |