List of usage examples for java.util Optional get
public T get()
From source file:net.sf.jabref.logic.exporter.CustomExportList.java
private void readPrefs(JabRefPreferences prefs) { formats.clear();/*from ww w . j ava2 s.c o m*/ list.clear(); int i = 0; List<String> s; while (!((s = prefs.getStringList(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i)).isEmpty())) { Optional<ExportFormat> format = createFormat(s); if (format.isPresent()) { formats.put(format.get().getConsoleName(), format.get()); list.add(s); } else { String customExportFormat = prefs.get(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i); LOGGER.error("Error initializing custom export format from string " + customExportFormat); } i++; } }
From source file:com.devicehive.application.security.WebSecurityConfig.java
@Bean public AuthenticationEntryPoint unauthorizedEntryPoint() { return (request, response, authException) -> { Optional<String> authHeader = Optional.ofNullable(request.getHeader(HttpHeaders.AUTHORIZATION)); if (authHeader.isPresent() && authHeader.get().startsWith(Constants.TOKEN_SCHEME)) { response.addHeader(HttpHeaders.WWW_AUTHENTICATE, Messages.OAUTH_REALM); } else {// ww w . ja v a 2s .c o m response.addHeader(HttpHeaders.WWW_AUTHENTICATE, Messages.BASIC_REALM); } response.setContentType(MediaType.APPLICATION_JSON_VALUE); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.getOutputStream().println(gson .toJson(new ErrorResponse(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage()))); }; }
From source file:com.ikanow.aleph2.security.db.AbstractDb.java
public Object loadBySpec(QueryComponent<JsonNode> spec) { Session s = null;/*from ww w.j a va2 s. com*/ try { Optional<JsonNode> ojs = getStore().getObjectBySpec(spec).get(); if (ojs.isPresent()) { s = (Session) deserialize(ojs.get()); } } catch (Exception e) { logger.error("Caught Exception loading from db:", e); } return s; }
From source file:net.sf.jabref.exporter.CustomExportList.java
private void readPrefs() { formats.clear();// ww w. j a va 2 s . c o m list.clear(); int i = 0; List<String> s; while (!((s = Globals.prefs.getStringList(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i)).isEmpty())) { Optional<ExportFormat> format = createFormat(s); if (format.isPresent()) { formats.put(format.get().getConsoleName(), format.get()); list.add(s); } else { String customExportFormat = Globals.prefs.get(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i); LOGGER.error("Error initializing custom export format from string " + customExportFormat); } i++; } }
From source file:ch.zweivelo.renderer.simple.shapes.PlaneTest.java
@Test public void testCalculateIntersectionDistance() throws Exception { Optional<Double> doubleOptional = plane.calculateIntersectionDistance(ray); assertNotNull(doubleOptional);//w w w . j a va2 s .c o m assertTrue(doubleOptional.isPresent()); assertEquals(1d, doubleOptional.get(), EPSILON); }
From source file:com.haulmont.cuba.web.gui.icons.IconResolverImpl.java
protected Resource getResource(String iconPath) { Optional<IconProvider> provider = iconProviders.stream().filter(p -> p.canProvide(iconPath)).findAny(); if (provider.isPresent()) { return provider.get().getIconResource(iconPath); }//from w w w.jav a2 s . com log.warn("There is no IconProvider for the given icon: {}", iconPath); return null; }
From source file:org.trustedanalytics.servicebroker.yarn.config.HadoopConfig.java
@Bean public Configuration getHadoopConfiguration() throws LoginException, IOException { Configuration hadoopConf = new Configuration(false); Optional<Map<String, String>> hadoopParams = HadoopConfigurationHelper .getHadoopConfFromJson(configuration.getYarnProvidedParams()); HadoopConfigurationHelper.mergeConfiguration(hadoopConf, hadoopParams.get()); return hadoopConf; }
From source file:com.uber.hoodie.common.util.ParquetUtils.java
/** * Read the rowKey list matching the given filter, from the given parquet file. If the filter is empty, * then this will return all the rowkeys. * * @param filePath The parquet file path. * @param configuration configuration to build fs object * @param filter record keys filter * @return Set Set of row keys matching candidateRecordKeys *///from w w w .j a v a 2s . com public static Set<String> filterParquetRowKeys(Configuration configuration, Path filePath, Set<String> filter) { Optional<RecordKeysFilterFunction> filterFunction = Optional.empty(); if (CollectionUtils.isNotEmpty(filter)) { filterFunction = Optional.of(new RecordKeysFilterFunction(filter)); } Configuration conf = new Configuration(configuration); conf.addResource(getFs(filePath.toString(), conf).getConf()); Schema readSchema = HoodieAvroUtils.getRecordKeySchema(); AvroReadSupport.setAvroReadSchema(conf, readSchema); AvroReadSupport.setRequestedProjection(conf, readSchema); ParquetReader reader = null; Set<String> rowKeys = new HashSet<>(); try { reader = AvroParquetReader.builder(filePath).withConf(conf).build(); Object obj = reader.read(); while (obj != null) { if (obj instanceof GenericRecord) { String recordKey = ((GenericRecord) obj).get(HoodieRecord.RECORD_KEY_METADATA_FIELD).toString(); if (!filterFunction.isPresent() || filterFunction.get().apply(recordKey)) { rowKeys.add(recordKey); } } obj = reader.read(); } } catch (IOException e) { throw new HoodieIOException("Failed to read row keys from Parquet " + filePath, e); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { // ignore } } } return rowKeys; }
From source file:net.sf.jabref.logic.fulltext.DoiResolution.java
@Override public Optional<URL> findFullText(BibEntry entry) throws IOException { Objects.requireNonNull(entry); Optional<URL> pdfLink = Optional.empty(); Optional<DOI> doi = entry.getFieldOptional(FieldName.DOI).flatMap(DOI::build); if (doi.isPresent()) { String sciLink = doi.get().getURIAsASCIIString(); // follow all redirects and scan for a single pdf link if (!sciLink.isEmpty()) { try { Connection connection = Jsoup.connect(sciLink); connection.followRedirects(true); connection.ignoreHttpErrors(true); // some publishers are quite slow (default is 3s) connection.timeout(5000); Document html = connection.get(); // scan for PDF Elements elements = html.body().select("[href]"); List<Optional<URL>> links = new ArrayList<>(); for (Element element : elements) { String href = element.attr("abs:href"); // Only check if pdf is included in the link // See https://github.com/lehner/LocalCopy for scrape ideas if (href.contains("pdf") && MimeTypeDetector.isPdfContentType(href)) { links.add(Optional.of(new URL(href))); }//www . j a v a 2 s . c o m } // return if only one link was found (high accuracy) if (links.size() == 1) { LOGGER.info("Fulltext PDF found @ " + sciLink); pdfLink = links.get(0); } } catch (IOException e) { LOGGER.warn("DoiResolution fetcher failed: ", e); } } } return pdfLink; }