protected static Set < URI > getValidDatasetURIsHelper ( Collection < URI > allDatasetURIs , Set < URI > disabledURISet , Path datasetCommonRoot ) { if ( allDatasetURIs == null || allDatasetURIs . isEmpty ( ) ) { return ImmutableSet . of ( ) ; } Comparator < URI > pathLengthComparator = new Comparator < URI > ( ) { public int compare ( URI c1 , URI c2 ) { return c1 . getPath ( ) . length ( ) - c2 . getPath ( ) . length ( ) ; } } ; List < URI > sortedDatasetsList = new ArrayList < URI > ( allDatasetURIs ) ; // sort the URI based on the path length to make sure the parent path appear before children Collections . sort ( sortedDatasetsList , pathLengthComparator ) ; TreeSet < URI > uriSet = new TreeSet < URI > ( ) ; Set < URI > noneLeaf = new HashSet < URI > ( ) ; for ( URI u : sortedDatasetsList ) { // filter out none common root if ( PathUtils . isAncestor ( datasetCommonRoot , new Path ( u . getPath ( ) ) ) ) { URI floor = uriSet . floor ( u ) ; // check for ancestor Paths if ( floor != null && PathUtils . isAncestor ( new Path ( floor . getPath ( ) ) , new Path ( u . getPath ( ) ) ) ) { noneLeaf . add ( floor ) ; } uriSet . add ( u ) ; } } // only get the leaf nodes Set < URI > validURISet = new HashSet < URI > ( ) ; for ( URI u : uriSet ) { if ( ! noneLeaf . contains ( u ) ) { validURISet . add ( u ) ; } } // remove disabled URIs for ( URI disable : disabledURISet ) { if ( validURISet . remove ( disable ) ) { log . info ( "skip disabled dataset " + disable ) ; } else { log . info ( "There's no URI " + disable + " available in validURISet." ) ; } } return validURISet ; }
Extended signature for testing convenience .