@Test void testLoadingInexistingResourceReturnsAnEmptyCollection() throws Exception { Set<String> result = new DictionaryLoader<Set<String>>(HashSet::new, null).loadCachedFromResource("hello.xml", "hello"); assertTrue(result.isEmpty()); }
public E loadCachedFromResource(String path, String dictionaryName) { return resourceCache.computeIfAbsent(path, e -> { try { E result = loadFromResource(path); LOG.info("Succeeded to load " + dictionaryName + "."); return result; } catch (IOException ioe) { LOG.error("Failed to load " + dictionaryName + ":" + path + ": " + ioe.getMessage()); return supplier.get(); } }); }
DictionaryLoader { public E loadCachedFromResource(String path, String dictionaryName) { return resourceCache.computeIfAbsent(path, e -> { try { E result = loadFromResource(path); LOG.info("Succeeded to load " + dictionaryName + "."); return result; } catch (IOException ioe) { LOG.error("Failed to load " + dictionaryName + ":" + path + ": " + ioe.getMessage()); return supplier.get(); } }); } }
DictionaryLoader { public E loadCachedFromResource(String path, String dictionaryName) { return resourceCache.computeIfAbsent(path, e -> { try { E result = loadFromResource(path); LOG.info("Succeeded to load " + dictionaryName + "."); return result; } catch (IOException ioe) { LOG.error("Failed to load " + dictionaryName + ":" + path + ": " + ioe.getMessage()); return supplier.get(); } }); } DictionaryLoader(Supplier<E> supplier, BiConsumer<E, String> loader); }
DictionaryLoader { public E loadCachedFromResource(String path, String dictionaryName) { return resourceCache.computeIfAbsent(path, e -> { try { E result = loadFromResource(path); LOG.info("Succeeded to load " + dictionaryName + "."); return result; } catch (IOException ioe) { LOG.error("Failed to load " + dictionaryName + ":" + path + ": " + ioe.getMessage()); return supplier.get(); } }); } DictionaryLoader(Supplier<E> supplier, BiConsumer<E, String> loader); E loadCachedFromResource(String path, String dictionaryName); E loadCachedFromFile(File file, String dictionaryName); }
DictionaryLoader { public E loadCachedFromResource(String path, String dictionaryName) { return resourceCache.computeIfAbsent(path, e -> { try { E result = loadFromResource(path); LOG.info("Succeeded to load " + dictionaryName + "."); return result; } catch (IOException ioe) { LOG.error("Failed to load " + dictionaryName + ":" + path + ": " + ioe.getMessage()); return supplier.get(); } }); } DictionaryLoader(Supplier<E> supplier, BiConsumer<E, String> loader); E loadCachedFromResource(String path, String dictionaryName); E loadCachedFromFile(File file, String dictionaryName);  }