private RepositoryResource compareNonProductResourceAppliesTo ( RepositoryResource res1 , RepositoryResource res2 ) { // all types other than INSTALLS or TOOLS use appliesTo to determine which is the higher level String res1AppliesTo = ( ( ApplicableToProduct ) res1 ) . getAppliesTo ( ) ; String res2AppliesTo = ( ( ApplicableToProduct ) res2 ) . getAppliesTo ( ) ; // on the basis that we will work with the appliesTo of a resource, if we find one that has an applies to // and one that doesn't we will the one WITH the applies to is assumed to be newer (if both null we look // at the version field) if ( res1AppliesTo == null && res2AppliesTo == null ) { // if both appliesTo are null look at the versions return getNonProductResourceWithHigherVersion ( res1 , res2 ) ; } else if ( res1AppliesTo == null || res2AppliesTo == null ) { // if one of them is null we can't compare them so return res1 return res1 ; } MinAndMaxVersion res1MinMax = getMinAndMaxAppliesToVersionFromAppliesTo ( res1AppliesTo ) ; MinAndMaxVersion res2MinMax = getMinAndMaxAppliesToVersionFromAppliesTo ( res2AppliesTo ) ; // compare the versions and return the resource that applies to the higher minimum version if ( res1MinMax . min . compareTo ( res2MinMax . min ) > 0 ) { return res1 ; } else if ( res1MinMax . min . compareTo ( res2MinMax . min ) == 0 ) { // if they apply to the same minimum version then select the one with the highest max versions if ( res1MinMax . max . compareTo ( res2MinMax . max ) > 0 ) { return res1 ; } else if ( res1MinMax . max . compareTo ( res2MinMax . max ) < 0 ) { return res2 ; } else { // if they are still the same decide on the version return getNonProductResourceWithHigherVersion ( res1 , res2 ) ; } } else { return res2 ; } }
This routine handles non product resources