String (final File file) { Element settingsXmlRoot; try { settingsXmlRoot = JDOMUtil.load(file); } catch (JDOMException | IOException e) { return null; } Optional<String> maybeRepository = KNOWN_NAMESPACES.stream() .map(it -> settingsXmlRoot.getChildText("localRepository", it)) .filter(it -> it != null && !isEmpty(it)) .findFirst(); return maybeRepository.orElse(null); }