Java Reference
In-Depth Information
L ISTING 12.4
Continued
if (v1!=v2)
return v1 - v2;
} else {
// we have at least a non-number, so compare them lexicographically
// see JNLP specs, Appendix A
return as[i].compareTo(as1[i]);
}
}//-for
// if we arrive here the two versionIds are logically equal
return 0;
12
}
public static boolean isNumber(String s){
try {
Integer.valueOf(s);
return true;
}
catch(NumberFormatException _ex) {
//don't care
}
return false;
}
/**
* Implements the superclass method
*/
public int compareTo(Object obj) {
Versionable value = null;
if (obj instanceof String)
value = createVersionable((String)obj);
if (obj instanceof Versionable)
value = (Versionable)obj;
if (value==null) {
throw new ClassCastException(“Cannot cast to Versionable or
String classes”);
}
//begins comparation
// remember that
// <0 : this < value
// =0 : this = value
// >0 : this > value
Search WWH ::




Custom Search