List of usage examples for java.util Optional of
public static <T> Optional<T> of(T value)
From source file:com.atlassian.connect.spring.internal.AtlassianConnectContextModelAttributeProvider.java
private Optional<String> getHostBaseUrlFromQueryParameters() { String hostUrl = request.getParameter("xdm_e"); String contextPath = request.getParameter("cp"); Optional<String> optionalBaseUrl = Optional.empty(); if (!StringUtils.isEmpty(hostUrl)) { if (!StringUtils.isEmpty(contextPath)) { optionalBaseUrl = Optional.of(hostUrl + contextPath); } else {// w w w . j a v a 2s .c o m optionalBaseUrl = Optional.of(hostUrl); } } return optionalBaseUrl; }
From source file:net.sf.jabref.logic.fetcher.ScienceDirect.java
@Override public Optional<URL> findFullText(BibEntry entry) throws IOException { Objects.requireNonNull(entry); Optional<URL> pdfLink = Optional.empty(); // Try unique DOI first Optional<DOI> doi = DOI.build(entry.getField("doi")); if (doi.isPresent()) { // Available in catalog? try {/*w w w . ja v a 2 s. c om*/ String sciLink = getUrlByDoi(doi.get().getDOI()); if (!sciLink.isEmpty()) { // Retrieve PDF link Document html = Jsoup.connect(sciLink).ignoreHttpErrors(true).get(); Element link = html.getElementById("pdfLink"); if (link != null) { LOGGER.info("Fulltext PDF found @ ScienceDirect."); pdfLink = Optional.of(new URL(link.attr("pdfurl"))); } } } catch (UnirestException e) { LOGGER.warn("ScienceDirect API request failed", e); } } return pdfLink; }
From source file:com.github.horrorho.inflatabledonkey.cloud.clients.KeyBagClient.java
static Optional<KeyBag> keyBag(CloudKit.RecordRetrieveResponse response, ProtectionZone zone) { Optional<byte[]> keyBagData = field(response.getRecord(), "keybagData", zone::decrypt); if (!keyBagData.isPresent()) { logger.warn("-- keyBag() - failed to acquire key bag"); return Optional.empty(); }//from w w w .ja va 2 s .co m Optional<byte[]> secret = field(response.getRecord(), "secret", zone::decrypt); if (!secret.isPresent()) { logger.warn("-- keyBag() - failed to acquire key bag pass code"); return Optional.empty(); } KeyBag keyBag = KeyBagFactory.create(keyBagData.get(), secret.get()); return Optional.of(keyBag); }
From source file:net.sf.jabref.logic.fulltext.SpringerLink.java
@Override public Optional<URL> findFullText(BibEntry entry) throws IOException { Objects.requireNonNull(entry); Optional<URL> pdfLink = Optional.empty(); // Try unique DOI first Optional<DOI> doi = entry.getFieldOptional(FieldName.DOI).flatMap(DOI::build); if (doi.isPresent()) { // Available in catalog? try {// w ww.j av a2 s . co m HttpResponse<JsonNode> jsonResponse = Unirest.get(API_URL).queryString("api_key", API_KEY) .queryString("q", String.format("doi:%s", doi.get().getDOI())).asJson(); JSONObject json = jsonResponse.getBody().getObject(); int results = json.getJSONArray("result").getJSONObject(0).getInt("total"); if (results > 0) { LOGGER.info("Fulltext PDF found @ Springer."); pdfLink = Optional.of(new URL("http", CONTENT_HOST, String.format("/content/pdf/%s.pdf", doi.get().getDOI()))); } } catch (UnirestException e) { LOGGER.warn("SpringerLink API request failed", e); } } return pdfLink; }
From source file:org.openmhealth.shim.ihealth.mapper.IHealthBodyWeightDataPointMapper.java
@Override protected Optional<DataPoint<BodyWeight>> asDataPoint(JsonNode listEntryNode, Integer measureUnitMagicNumber) { checkNotNull(measureUnitMagicNumber); IHealthBodyWeightUnit bodyWeightUnitType = IHealthBodyWeightUnit.fromIntegerValue(measureUnitMagicNumber); MassUnit bodyWeightUnit = bodyWeightUnitType.getOmhUnit(); double bodyWeightValue = getBodyWeightValueForUnitType(listEntryNode, bodyWeightUnitType); if (bodyWeightValue == 0) { return Optional.empty(); }//from w ww .java2 s. com BodyWeight.Builder bodyWeightBuilder = new BodyWeight.Builder( new MassUnitValue(bodyWeightUnit, bodyWeightValue)); getEffectiveTimeFrameAsDateTime(listEntryNode).ifPresent(bodyWeightBuilder::setEffectiveTimeFrame); getUserNoteIfExists(listEntryNode).ifPresent(bodyWeightBuilder::setUserNotes); BodyWeight bodyWeight = bodyWeightBuilder.build(); return Optional.of(new DataPoint<>(createDataPointHeader(listEntryNode, bodyWeight), bodyWeight)); }
From source file:com.ikanow.aleph2.distributed_services.utils.TestKafkaUtils.java
License:asdf
@Test public void test_kafkaConnectionFromZookeeper() throws Exception { final ObjectMapper mapper = BeanTemplateUtils.configureMapper(Optional.empty()); assertEquals(Integer.toString(_cds.getKafkaBroker().getBrokerPort()), KafkaUtils .getBrokerListFromZookeeper(_cds.getCuratorFramework(), Optional.empty(), mapper).split(":")[1]); assertEquals(Integer.toString(_cds.getKafkaBroker().getBrokerPort()), KafkaUtils/*from w w w.ja v a 2 s .c o m*/ .getBrokerListFromZookeeper(_cds.getCuratorFramework(), Optional.of("/brokers/ids"), mapper) .split(":")[1]); }
From source file:lumbermill.internal.http.PostHandler.java
public PostHandler(Codec<IN> codec, OnPostCreatedCallback callback) { this.httpHandlerSupplier = Optional.of(new CodecHttpHandlerWrapper(codec)); this.callback = callback; }
From source file:com.google.testing.web.screenshotter.Screenshotter.java
/** Returns a copy of this configured to take a screenshot of element. */ public Screenshotter of(WebElement element) { return new Screenshotter(this.url, Optional.of(element), this.excluding); }
From source file:com.vsct.dt.strowgr.admin.template.locator.UriTemplateLocator.java
public Optional<String> readTemplate(String uri) { try {//from w w w. jav a 2s .c o m HttpGet getTemplate = new HttpGet(uri); getTemplate.addHeader("Content-Type", "text/plain; charset=utf-8"); LOGGER.debug("get template {}", uri); return client.execute(getTemplate, (response) -> { Optional<String> result = Optional.empty(); int status = response.getStatusLine().getStatusCode(); if (status >= 200 && status < 300) { HttpEntity entity = response.getEntity(); String entitySer = EntityUtils.toString(entity, "UTF-8"); if (entitySer == null) { throw new IllegalStateException("template from " + uri + " has null content."); } else { LOGGER.debug("template from " + uri + " starts with " + entitySer.substring(0, Math.max(20, entitySer.length()))); } result = Optional.of(entitySer); } else if (status != 404) { throw new ClientProtocolException("Unexpected response status: " + status); } return result; }); } catch (IOException e) { LOGGER.error("Can't retrieve template from " + uri, e); throw new RuntimeException(e); } }
From source file:com.epam.training.service.impl.DefaultSergiiService.java
private Optional<CatalogUnawareMediaModel> findExistingLogo(final String logoCode) { final FlexibleSearchQuery fQuery = new FlexibleSearchQuery(FIND_LOGO_QUERY); fQuery.addQueryParameter("code", logoCode); try {//from w w w. j a v a 2 s. c o m return Optional.of(flexibleSearchService.searchUnique(fQuery)); } catch (final SystemException e) { return Optional.empty(); } }