private static ImmutableMap < Symbol , File > loadDocIdToFileMap ( final Optional < File > inputFileListFile , final Optional < File > inputFileMapFile ) throws IOException { checkArgument ( inputFileListFile . isPresent ( ) || inputFileMapFile . isPresent ( ) ) ; final Optional < ImmutableList < File > > fileList ; if ( inputFileListFile . isPresent ( ) ) { fileList = Optional . of ( FileUtils . loadFileList ( inputFileListFile . get ( ) ) ) ; } else { fileList = Optional . absent ( ) ; } final Optional < ImmutableMap < Symbol , File > > fileMap ; if ( inputFileMapFile . isPresent ( ) ) { fileMap = Optional . of ( FileUtils . loadSymbolToFileMap ( inputFileMapFile . get ( ) ) ) ; } else { fileMap = Optional . absent ( ) ; } // sanity checks if ( fileList . isPresent ( ) ) { // file list may not contain duplicates final boolean containsDuplicates = ImmutableSet . copyOf ( fileList . get ( ) ) . size ( ) != fileList . get ( ) . size ( ) ; if ( containsDuplicates ) { throw new RuntimeException ( "Input file list contains duplicates" ) ; } } // if both a file map and a file list are given, they must be compatible. if ( fileList . isPresent ( ) && fileMap . isPresent ( ) ) { if ( fileList . get ( ) . size ( ) != fileMap . get ( ) . size ( ) ) { throw new RuntimeException ( "Input file list and file map do not match in size (" + fileList . get ( ) . size ( ) + " vs " + fileMap . get ( ) . size ( ) ) ; } final boolean haveExactlyTheSameFiles = ImmutableSet . copyOf ( fileList . get ( ) ) . equals ( ImmutableSet . copyOf ( fileMap . get ( ) . values ( ) ) ) ; if ( ! haveExactlyTheSameFiles ) { throw new RuntimeException ( "Input file list and file map do not containe exactly the same files" ) ; } } // output if ( fileMap . isPresent ( ) ) { return fileMap . get ( ) ; } else { // if we only had a file list as input, we make a fake doc-id-to-file-map using // the absolute path as the document ID. This won't get output, so it doesn't matter // that this is a little hacky final Function < File , Symbol > fileNameAsSymbolFunction = compose ( SymbolUtils . symbolizeFunction ( ) , FileUtils . toAbsolutePathFunction ( ) ) ; return Maps . uniqueIndex ( fileList . get ( ) , fileNameAsSymbolFunction ) ; } }
Gets a doc - id - to - file map for the input either directly or making a fake one based on an input file list .