/** * Method to return the one and only singleton uniqueInstance. */ public static Options instance() { if (mUniqueInstance == null) mUniqueInstance = new Options(); return mUniqueInstance; }
/** * Parse command-line arguments and set the appropriate values. */ public boolean parseArgs(String[] args) { for (int i = 0; i < args.length; i++) { switch (args[i]) { case "-s": // Set the file separator character. mInputSeparator = args[++i]; break; case "-v": mVerbose = true; break; default: printUsage(); return false; } } return true; }
/** * Display @a string if the program is run in verbose mode. */ static void display(String string) { if (Options.getInstance().getVerbose()) System.out.println(string); }
/** * Conditionally prints the @a string depending on the current * setting of the Options singleton. */ private void print(String string) { if (Options.instance().getDiagnosticsEnabled()) System.out.println(string); } }
/** * Main entry point into the program. */ static public void main(String[] argv) { // Parse the options. Options.getInstance().parseArgs(argv); // Warmup the stream pool. warmupThreadPool(); // Run all the tests. runTests(); // Print the results. System.out.println(RunTimer.getTimingResults()); }
Options.getInstance().parseArgs(args); Options.getInstance().getInputSeparator()); Options.getInstance().getInputSeparator());
/** * Store the search results. */ private static void storeResults(String testConfig, long stopTime, List<List<SearchResults>> listOfListOfSearchResults) { // Print the number of times each phrase matched the input. mResultsMap.put(stopTime, "The search returned = " // Count the number of matches. + listOfListOfSearchResults.stream() .mapToInt(list -> list.stream().mapToInt(SearchResults::size).sum()) .sum() + " phrase matches in " + stopTime + " milliseconds for " + testConfig); // Print the matching titles. if (Options.getInstance().isVerbose()) printTitles(listOfListOfSearchResults); }
/** * Clears the filter directories. */ private void deleteDownloadedImages() { int deletedFiles = deleteSubFolders(Options.instance().getDirectoryPath()); System.out.println(TAG + ": " + deletedFiles + " previously downloaded file(s) deleted"); }
/** * Run the program. */ private void run() { // Delete any the filtered images from the previous run. deleteDownloadedImages(); // Get the list of files to the downloaded images. List<File> imageFiles = Options.instance().getUrlList() // Convert the URLs in the input list into a stream and // process them in parallel. .parallelStream() // Transform URL to a File by downloading each image via // its URL. This call ensures the common fork/join thread // pool is expanded to handle the blocking image download. .map(this::downloadAndStoreImage) // Terminate the stream and collect the results into list // of images. .collect(Collectors.toList()); System.out.println(TAG + ": downloaded and stored " + imageFiles.size() + " images"); }
String rootUri = Options.instance().getRootUri();
/** * Main entry point into the program. */ static public void main(String[] argv) { // Parse the options. Options.getInstance().parseArgs(argv); // Warmup the stream pool. warmupThreadPool(); // Run the tests sequentially. runTests(false); // Run the tests in parallel. runTests(true); // Print the results. System.out.println(RunTimer.getTimingResults()); }
/** * Display @a string if the program is run in verbose mode. */ private static void display(String string) { if (Options.getInstance().getVerbose()) System.out.println(string); }
/** * Store the search results. */ private static void storeResults(String testConfig, long stopTime, List<List<SearchResults>> listOfListOfSearchResults) { // Print the number of times each phrase matched the input. mResultsMap.put(stopTime, "The search returned = " // Count the number of matches. + listOfListOfSearchResults.stream() .mapToInt(list -> list.stream().mapToInt(SearchResults::size).sum()) .sum() + " phrase matches in " + stopTime + " milliseconds for " + testConfig); // Print the matching titles. if (Options.getInstance().isVerbose()) printTitles(listOfListOfSearchResults); }
/** * Store the image on the local file system. * * @return The stored image file. */ public File store() { // Get a reference to the file in which the image will be // stored. File imageFile = new File(new File(Options.instance().getDirectoryPath()), getFileName()); // Store the image using try-with-resources try (FileOutputStream outputFile = new FileOutputStream(imageFile)) { // Write the image to the output file. PlatSpec.writeImageFile(outputFile, this); return imageFile; } catch (Exception e) { e.printStackTrace(); return null; } } }
Options.getInstance().parseArgs(args);
/** * Return the one and only singleton unique instance. */ public static Options getInstance() { if (sInstance == null) sInstance = new Options(); return sInstance; }