List of usage examples for java.util Optional of
public static <T> Optional<T> of(T value)
From source file:net.hamnaberg.json.ValueFactory.java
public static Optional<Value> createOptionalValue(JsonNode value) { if (value == null) { return Optional.empty(); }//from w w w.jav a2 s.c o m Value v = createValue(value); if (v.isNull()) { return Optional.empty(); } return Optional.of(v); }
From source file:com.formkiq.core.util.Zips.java
/** * Find bytes in zip by name./*from w ww . j a v a 2s. co m*/ * @param bytes byte[] * @param name {@link String} * @return {@link Optional} * @throws IOException IOException */ public static Optional<byte[]> findInZip(final byte[] bytes, final String name) throws IOException { Map<String, byte[]> map = Zips.extractZipToMap(bytes); if (map.containsKey(name)) { return Optional.of(map.get(name)); } return Optional.empty(); }
From source file:com.facebook.buck.util.unarchive.Untar.java
public static Untar bzip2Unarchiver() { return new Untar(Optional.of(CompressorStreamFactory.BZIP2)); }
From source file:com.orange.ngsi2.utility.Utils.java
static public List<Entity> createListEntitiesReference() { List<Entity> entities = new ArrayList<Entity>(); Entity entityRoomDC = new Entity("DC_S1-D41", "Room"); entityRoomDC.setAttributes("temperature", new Attribute(35.6)); entities.add(entityRoomDC);//ww w . jav a2s. com Entity entityRoomBoe = new Entity("Boe-Idearium", "Room"); entityRoomBoe.setAttributes("temperature", new Attribute(22.5)); entities.add(entityRoomBoe); Entity entityCar = new Entity("P-9873-K", "Car"); Attribute speedAttribute = new Attribute(100); speedAttribute.setType(Optional.of("number")); Metadata accuracyMetadata = new Metadata(); accuracyMetadata.setValue(2); Metadata timestampMetadata = new Metadata(); timestampMetadata.setValue("2015-06-04T07:20:27.378Z"); timestampMetadata.setType("date"); speedAttribute.addMetadata("accuracy", accuracyMetadata); speedAttribute.addMetadata("timestamp", timestampMetadata); entityCar.setAttributes("speed", speedAttribute); entities.add(entityCar); return entities; }
From source file:cloudfoundry.norouter.f5.client.SubCollection.java
public SubCollection(@JsonProperty("link") URI link, @JsonProperty("items") Collection<T> items) { this.link = link; if (items == null) { this.items = Optional.empty(); } else {/*from ww w.java 2s . c o m*/ items = Collections.unmodifiableCollection(new ArrayList<>(items)); this.items = Optional.of(items); } }
From source file:de.ii.xtraplatform.feature.provider.wfs.FeatureProviderDataWfs.java
@Override @Value.Derived//from w w w. jav a 2s . co m public Optional<String> getDataSourceUrl() { URIBuilder uriBuilder = new URIBuilder(getConnectionInfo().getUri()); return Optional.of( uriBuilder.addParameter("SERVICE", "WFS").addParameter("REQUEST", "GetCapabilities").toString()); }
From source file:org.openmhealth.shim.withings.mapper.WithingsHeartRateDataPointMapper.java
@Override public Optional<Measure.Builder<HeartRate, ?>> newMeasureBuilder(JsonNode measuresNode) { Optional<BigDecimal> value = getValueForMeasureType(measuresNode, HEART_RATE); if (!value.isPresent()) { return empty(); }/*from ww w . j a va 2s .c o m*/ return Optional.of(new HeartRate.Builder(value.get())); }
From source file:org.lendingclub.mercator.aws.ASGScanner.java
@Override public Optional<String> computeArn(JsonNode n) { return Optional.of(n.path("aws_autoScalingGroupARN").asText()); }
From source file:net.sf.jabref.importer.fetcher.BibsonomyScraper.java
/** * Return a BibEntry by looking up the given url from the BibSonomy scraper. * @param entryUrl/*from w w w . jav a 2 s . c o m*/ * @return */ public static Optional<BibEntry> getEntry(String entryUrl) { try { // Replace special characters by corresponding sequences: String cleanURL = entryUrl.replace("%", "%25").replace(":", "%3A").replace("/", "%2F") .replace("?", "%3F").replace("&", "%26").replace("=", "%3D"); URL url = new URL( BibsonomyScraper.BIBSONOMY_SCRAPER + cleanURL + BibsonomyScraper.BIBSONOMY_SCRAPER_POST); String bibtex = new URLDownload(url).downloadToString(StandardCharsets.UTF_8); BibtexParser bp = new BibtexParser(new StringReader(bibtex)); ParserResult pr = bp.parse(); if ((pr != null) && pr.getDatabase().hasEntries()) { return Optional.of(pr.getDatabase().getEntries().iterator().next()); } else { return Optional.empty(); } } catch (IOException ex) { LOGGER.warn("Could not download entry", ex); return Optional.empty(); } catch (RuntimeException ex) { LOGGER.warn("Could not get entry", ex); return Optional.empty(); } }
From source file:de.is24.aws.instancemetadataserver.RemoteHostRoleNameProducer.java
private Optional<String> toRoleName(String hostName) { return Optional.of(hostName).flatMap(this::getHostPart).flatMap(this::stripHostNr) .flatMap(this::unifyHamAndBerToPro).map(this::addRzPrefix); }