/** * Return the one and only singleton unique instance. */ public static Options getInstance() { if (sInstance == null) sInstance = new Options(); return sInstance; }
/** * The JVM requires a static main() entry point to run the console version of * the ImageTaskGang app. */ public static void main(String[] args) { System.out.println("Starting ImageTaskGangTest"); // Initializes the Options singleton. Options.instance().parseArgs(args); // Run all the tests. runTests(); System.out.println("Ending ImageTaskGangTest"); }
/** * Parse command-line arguments and set the appropriate values. */ public boolean parseArgs(String argv[]) { if (argv != null) { for (int argc = 0; argc < argv.length; argc += 2) if (argv[argc].equals("-d")) mDiagnosticsEnabled = argv[argc + 1].equals("true"); else if (argv[argc].equals("-s")) { mInputSource = getInputSource(argv[argc + 1]); } else { printUsage(); return false; } return true; } else return false; }
/** * Returns the appropriate list of URLs, i.e., either pointing to * the local device or to a remote server. */ protected List<List<URL>> getDefaultUrlList(boolean local) throws MalformedURLException { return local ? getDefaultResourceUrlList() : getDefaultUrlList(); }
/** * This is the entry point into the test driver program. */ public static void main(String[] args) throws Throwable { System.out.println("Starting SearchStreamGangTest"); // Parse the command-line arguments. Options.getInstance().parseArgs(args); // All the input is initialized here. List<List<CharSequence>> inputData = new ArrayList<List<CharSequence>>() { { // Create a list of input from the complete works of // William Shakespeare. add(TestDataFactory // Split input by input separator from Options singleton. .getSharedInput(sSHAKESPEARE_DATA_FILE, Options.getInstance().getInputSeparator())); } }; // Get the list of input phases to find. List<String> phaseList = TestDataFactory.getPhraseList(sPHASE_LIST_FILE); // Create/run StreamGangs to search for the phases to find. runTests(phaseList, inputData); System.out.println("Ending SearchStreamGangTest"); }
/** * Clears the filter directories. */ private static void deleteFilteredImages() { int deletedFiles = 0; // Delete all the filter directories. for (Filter filter : mFilters) deletedFiles += deleteSubFolders (new File(Options.instance().getDirectoryPath(), filter.getName()).getAbsolutePath()); System.out.println(deletedFiles + " previously downloaded file(s) deleted"); }
/** * Warm up the threads in the thread pool so the timing results * will be more accurate. */ private static void warmUpThreadPool() { System.out.println("Warming up the thread pool"); // Delete any the filtered images from the previous run. deleteFilteredImages(); // Create and run the ImageTaskCompletionServiceFixed test to // warm up threads in the thread pool. ImageTaskGang taskGang = new ImageTaskCompletionServiceFixed(mFilters, Options.instance().getUrlLists()); taskGang.run(); // Run the garbage collector to avoid perturbing the test. System.gc(); System.out.println("End warming up the thread pool"); }
/** * Parse command-line arguments and set the appropriate values. */ public boolean parseArgs(String[] args) { for (int i = 0; i < args.length; i++) { if (args[i].equals("-s")) // Set the file separator character. mInputSeparator = args[++i]; else if (args[i].equals("-v")) mVerbose = true; else { printUsage(); return false; } } return true; }
/** * Print out the search results. */ private void printResults(String test, List<List<SearchResults>> listOfListOfSearchResults) { System.out.println(test + ": The search returned " + listOfListOfSearchResults.stream() .mapToInt(list -> list.stream().mapToInt(SearchResults::size).sum()) .sum() + " phrase matches for " + getInput().size() + " input strings"); // Print out the titles. if (Options.getInstance().isVerbose()) printPhrases(listOfListOfSearchResults); }
/** * Return an Iterator over one or more input URL Lists. */ public Iterator<List<URL>> getUrlIterator() { List<List<URL>> urlLists = getUrlLists(); return urlLists != null && urlLists.size() > 0 ? urlLists.iterator() : null; }
return getDefaultUrlList(false); return getDefaultUrlList(true);
File externalFile = new File(Options.instance().getDirectoryPath(), this.getName()); externalFile.mkdirs();
/** * Method to return the one and only singleton uniqueInstance. */ public static Options instance() { if (mUniqueInstance == null) mUniqueInstance = new Options(); return mUniqueInstance; }