FileDocCategorySizeDatePackage
DeweyDecimal.javaAPI DocGlassfish v2 API5526Fri May 04 22:33:24 BST 2007com.sun.enterprise.tools.verifier.apiscan.packaging

DeweyDecimal

public class DeweyDecimal extends Object

Fields Summary
private int
major
private int
minor
private int
micro
Constructors Summary
public DeweyDecimal()


      
    
public DeweyDecimal(String s)

        s = s.trim();
        int idxOfFirstDot = s.indexOf('.", 0);
        if (idxOfFirstDot == -1) {
            major = Integer.parseInt(s);
            return;
        } else {
            major = Integer.parseInt(s.substring(0, idxOfFirstDot));
        }
        int idxOfSecondDot = s.indexOf('.", idxOfFirstDot + 1);
        if (idxOfSecondDot == -1) {
            minor = Integer.parseInt(s.substring(idxOfFirstDot + 1));
            return;
        } else {
            minor =
                    Integer.parseInt(
                            s.substring(idxOfFirstDot + 1, idxOfSecondDot));
        }
        micro = Integer.parseInt(s.substring(idxOfSecondDot + 1));
    
Methods Summary
public booleanequals(java.lang.Object o)

        if (o == null) return false;
        try {
            DeweyDecimal other = (DeweyDecimal) o;
            return major == other.major && minor == other.minor &&
                    micro == other.micro;
        } catch (ClassCastException e) {
            return false;
        }
    
public inthashCode()

        return major + minor + micro;
    
public booleanisCompatible(com.sun.enterprise.tools.verifier.apiscan.packaging.DeweyDecimal another)

        if (another == null) return false;
        if (major < another.major) {
            return false;
        } else if (major == another.major) {
            if (minor < another.minor) {
                return false;
            } else if (minor == another.minor) {
                return micro >= another.micro;
            }
            //this.minor> another.minor && this.major==another.major, hence return true
            return true;
        }
        //this.major> another.major, hence return true
        return true;
    
public booleanisCompatible(java.lang.String another)

        if (another == null) return false;
        return isCompatible(new DeweyDecimal(another));
    
public static voidmain(java.lang.String[] args)

        if (args.length != 2) {
            System.out.println(
                    "Usage: " + DeweyDecimal.class.getName() + // NOI18N
                    " <s1 in the format 1.2.3> <s2 in the format 5.5.6>"); // NOI18N
            System.exit(1);
        }
        DeweyDecimal d1 = new DeweyDecimal(args[0]);
        DeweyDecimal d2 = new DeweyDecimal(args[1]);
        System.out.println(d1 + ".isCompatible(" + d1 + ")=" + d1.isCompatible( // NOI18N
                d1));
        System.out.println(d2 + ".isCompatible(" + d2 + ")=" + d2.isCompatible( // NOI18N
                d2));
        System.out.println(d1 + ".isCompatible(" + d2 + ")=" + d1.isCompatible( // NOI18N
                d2));
        System.out.println(d2 + ".isCompatible(" + d1 + ")=" + d2.isCompatible( // NOI18N
                d1));
        System.out.println(d1 + ".equals(" + d1 + ")=" + d1.equals(d1)); // NOI18N
        System.out.println(d2 + ".equals(" + d2 + ")=" + d2.equals(d2)); // NOI18N
        System.out.println(d1 + ".equals(" + d2 + ")=" + d1.equals(d2)); // NOI18N
        System.out.println(d2 + ".equals(" + d1 + ")=" + d2.equals(d1)); // NOI18N
        System.out.println(d1 + ".hashCode()=" + d1.hashCode()); // NOI18N
        System.out.println(d2 + ".hashCode()=" + d2.hashCode()); // NOI18N
    
public java.lang.StringtoString()

        return "" + major + "." + minor + "." + micro; // NOI18N