/** uncheck(Class::forName, "xxx"); */ public static <T, R> R uncheck(Function_WithExceptions<T, R> function, T t) { try { return function.apply(t); } catch (Exception exception) { throwAsUnchecked(exception); return null; } }
/** rethrowSupplier(() -> new StringJoiner(new String(new byte[]{77, 97, 114, 107}, "UTF-8"))), */ public static <T> Supplier<T> rethrowSupplier(Supplier_WithExceptions<T> function) { return () -> { try { return function.get(); } catch (Exception exception) { throwAsUnchecked(exception); return null; } }; }
/** * Factory method that retrieves the image associated with the @a * urlToDownload and creates an Image to encapsulate it. */ protected Image downloadImage(URL url) { return new Image(url, NetUtils.downloadContent(url)); }
/** * Search for a phrase in the input data. */ private static SearchResults searchForPhrase(String phrase, CharSequence inputData) { return new SearchResults (phrase, "", // Perform the processing (either sequentially or in // parallel) and return a list of Results. new PhraseMatchTask(inputData, phrase).compute()); }
/** * Return the one and only singleton unique instance. */ public static Options getInstance() { if (sInstance == null) sInstance = new Options(); return sInstance; }
/** .forEach(rethrowConsumer(name -> System.out.println(Class.forName(name)))); or .forEach(rethrowConsumer(ClassNameUtil::println)); */ public static <T> Consumer<T> rethrowConsumer(Consumer_WithExceptions<T> consumer) { return t -> { try { consumer.accept(t); } catch (Exception exception) { throwAsUnchecked(exception); } }; }
/** uncheck(() -> Class.forName("xxx")); */ public static void uncheck(Runnable_WithExceptions t) { try { t.accept(); } catch (Exception exception) { throwAsUnchecked(exception); } }
/** * 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 method searches the @a inputString for all occurrences of * the phrases to find. */ @Override public List<SearchResults> compute() { if (mPhraseList.size() < mMinSplitSize) return computeSequentially(); else // Compute position to split the phrase list and forward // to the splitPhraseList() method to perform the split. return splitPhraseList(mPhraseList.size() / 2); }
/** * Call @a runnable.run() and time how long it takes to run. */ public static void timeRun(Runnable runnable, String testName) { startTiming(); runnable.run(); stopTiming(); // Store the execution times into the results map. mResultsMap.put(testName, mExecutionTime); }
/** * Returns the file name from the URL this Image was * constructed from. */ public String getFileName() { return NetUtils.getFileNameForUrl(mSourceUrl); }
/** * This static factory method creates a new StremaOfFuturesCollector. * * @return A new StreamOfFuturesCollector() */ public static <T> Collector<CompletableFuture<T>, ?, CompletableFuture<Stream<T>>> toFuture() { return new StreamOfFuturesCollector<>(); } }
/** * Construct an Image from a byte array of @a imageData * downloaded from a URL @a source. */ public Image(URL sourceURL, byte[] imageData) { // Set the URL. mSourceUrl = sourceURL; // Initialize other data members. mFilterName = null; mSucceeded = true; // Decode the imageData into a BufferedImage. setImage(imageData); }
/** * Add a Result. */ public void add(int index) { mList.add(new Result(index)); }
/** * 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; }
/** * This template method calls the applyFilter() hook method (which * must be defined by a subclass) to filter the @a imageEntity * parameter and sets the filterName of the result to the name of * the filter. */ public Image filter(Image image) { // Call the applyFilter() hook method. Image filteredResult = applyFilter(image); filteredResult.setFilterName(this); return filteredResult; }
/** .map(rethrowFunction(name -> Class.forName(name))) or .map(rethrowFunction(Class::forName)) */ public static <T, R> Function<T, R> rethrowFunction(Function_WithExceptions<T, R> function) { return t -> { try { return function.apply(t); } catch (Exception exception) { throwAsUnchecked(exception); return null; } }; }
/** uncheck(() -> Class.forName("xxx")); */ public static <R> R uncheck(Supplier_WithExceptions<R> supplier) { try { return supplier.get(); } catch (Exception exception) { throwAsUnchecked(exception); return null; } }
/** * Method to return the one and only singleton uniqueInstance. */ public static Options instance() { if (mUniqueInstance == null) mUniqueInstance = new Options(); return mUniqueInstance; }