public int compareTo()

in src/main/java/org/apache/sling/commons/osgi/bundleversion/BundleVersionInfo.java [68:112]


    public int compareTo(BundleVersionInfo<?> other) {
        // Handle null values
        if(other == null) {
            throw new IllegalArgumentException("b is null, cannot compare");
        }
        
        // Handle non-bundles: we don't want them!
        if(!isBundle()) {
            throw new IllegalArgumentException("Not a bundle, cannot compare: " + this);
        }
        if(!other.isBundle()) {
            throw new IllegalArgumentException("Not a bundle, cannot compare:" + other);
        }
        
        // First compare symbolic names
        int result = getBundleSymbolicName().compareTo(other.getBundleSymbolicName());
        
        // Then compare versions
        if(result == EQUAL) {
            final Version va = getVersion();
            final Version vb = other.getVersion();
            if(va == null && vb == null) {
                // result = EQUAL
            } else if(vb == null) {
                result = A_GREATER;
            } else if(va == null) {
                result = B_GREATER;
            } else {
                result = va.compareTo(vb);
            }
        }
        
        // Then, if snapshots, compare modification times, more recent comes first
        if(result == EQUAL && isSnapshot()) {
            final long ma = getBundleLastModified();
            final long mb = other.getBundleLastModified();
            if(ma > mb) {
                result = A_GREATER;
            } else if(mb > ma) {
                result = B_GREATER;
            }
        }
        
        return result;
    }