/** * Factory method that creates a document from the file at the * given @a path. */ static Document fromPath(Path path) throws IOException { // Create a new document that contains all the bytes // of the file at the given path. Document document = new Document(new String(Files.readAllBytes(path))); // Set the name of the document. document.mName = path.getFileName().toString(); // Return the document. return document; } }
/** * Perform the computations sequentially at this point. */ private CharSequence computeSequentially() { // Used to concatenate the CharSequences together. StringBuilder stringBuilder = new StringBuilder(); // Iterate through the list of documents. for (Document doc : mDocsList) // Append the contents of each document. stringBuilder.append(doc.getContents()); // Return a CharSequence containing the contents of this // Shakespeare work. return stringBuilder.toString(); }
/** * Perform the computations sequentially. * * @return A list of search results that matched the phrases */ private List<SearchResults> computeSequential() { // The list of results. List<SearchResults> results = new ArrayList<>(); // Iterate through all the phrases in the document. for (String phrase : mPhraseList) { // Use a PhraseMatchTask to add the indices of all places // in the inputData where phrase matches. SearchResults searchResults = new PhraseMatchTask(mTitle, mDocument.getContents(), phrase, mParallelSearching).compute(); if (!searchResults.isEmpty()) // If phrase was found add it to the list of results. results.add(searchResults); } // Return the results. return results; } }
/** * Factory method that creates a document from the file at the * given @a path. */ static Document fromPath(Path path) throws IOException { // Create a new document that contains all the bytes // of the file at the given path. Document document = new Document(new String(Files.readAllBytes(path))); // Set the name of the document. document.mName = path.getFileName().toString(); // Return the document. return document; } }
mDocument.getContents(), phrase, mParallelSearching).fork());