@Test public void dirIfExists() { assertThat(ContextImpl.dirIfExists(null), is(Optional.empty())); assertThat(ContextImpl.dirIfExists("."), is(Optional.of(Paths.get(".")))); }
static public Optional<Path> dirIfExists(String path) { try { if (path == null || path.length() == 0) { return Optional.empty(); } Path dir = Paths.get(path); if (Files.isDirectory(dir)) { return Optional.of(dir); } else { return Optional.empty(); } } catch (Throwable t) { return Optional.empty(); } }
ContextImpl implements Context { static public Optional<Path> dirIfExists(String path) { try { if (path == null || path.length() == 0) { return Optional.empty(); } Path dir = Paths.get(path); if (Files.isDirectory(dir)) { return Optional.of(dir); } else { return Optional.empty(); } } catch (Throwable t) { return Optional.empty(); } } }
ContextImpl implements Context { static public Optional<Path> dirIfExists(String path) { try { if (path == null || path.length() == 0) { return Optional.empty(); } Path dir = Paths.get(path); if (Files.isDirectory(dir)) { return Optional.of(dir); } else { return Optional.empty(); } } catch (Throwable t) { return Optional.empty(); } } ContextImpl(Path baseDir, Path userDir, Path scriptFile, Config config); }
ContextImpl implements Context { static public Optional<Path> dirIfExists(String path) { try { if (path == null || path.length() == 0) { return Optional.empty(); } Path dir = Paths.get(path); if (Files.isDirectory(dir)) { return Optional.of(dir); } else { return Optional.empty(); } } catch (Throwable t) { return Optional.empty(); } } ContextImpl(Path baseDir, Path userDir, Path scriptFile, Config config); Prompter getPrompter(); void prompter(Prompter prompter); void baseDir(Path baseDir); void userDir(Path userDir); void scriptFile(Path scriptFile); @Override Logger logger(); @Override Path baseDir(); @Override Path withBaseDir(Path path); @Override Path withBaseDir(File file); @Override Path withBaseDir(String path); @Override Path scriptFile(); @Override Config config(); @Override Path userDir(); @Override Path withUserDir(Path path); @Override Path withUserDir(File file); @Override Path withUserDir(String path); @Override void fail(String message); @Override String prompt(String prompt, Object... args); @Override char[] passwordPrompt(String prompt, Object... args); static Path findUserDir(); static Optional<Path> dirIfExists(String path); }
ContextImpl implements Context { static public Optional<Path> dirIfExists(String path) { try { if (path == null || path.length() == 0) { return Optional.empty(); } Path dir = Paths.get(path); if (Files.isDirectory(dir)) { return Optional.of(dir); } else { return Optional.empty(); } } catch (Throwable t) { return Optional.empty(); } } ContextImpl(Path baseDir, Path userDir, Path scriptFile, Config config); Prompter getPrompter(); void prompter(Prompter prompter); void baseDir(Path baseDir); void userDir(Path userDir); void scriptFile(Path scriptFile); @Override Logger logger(); @Override Path baseDir(); @Override Path withBaseDir(Path path); @Override Path withBaseDir(File file); @Override Path withBaseDir(String path); @Override Path scriptFile(); @Override Config config(); @Override Path userDir(); @Override Path withUserDir(Path path); @Override Path withUserDir(File file); @Override Path withUserDir(String path); @Override void fail(String message); @Override String prompt(String prompt, Object... args); @Override char[] passwordPrompt(String prompt, Object... args); static Path findUserDir(); static Optional<Path> dirIfExists(String path);  }