List of usage examples for java.util Optional of
public static <T> Optional<T> of(T value)
From source file:com.orange.ngsi2.model.AttributeTest.java
@Test public void serializationAttributeWithMetadataTest() throws JsonProcessingException { Attribute attribute = new Attribute(23.5); attribute.setType(Optional.of("float")); Metadata metadata = new Metadata(); metadata.setType("mesure"); metadata.setValue("celsius"); HashMap<String, Metadata> metadatas = new HashMap<String, Metadata>(); metadatas.put("metadata1", metadata); attribute.setMetadata(metadatas);/*from www. j ava2 s .c o m*/ String json = Utils.objectMapper.writeValueAsString(attribute); String jsonString = "{\"value\":23.5,\"type\":\"float\",\"metadata\":{\"metadata1\":{\"value\":\"celsius\",\"type\":\"mesure\"}}}"; assertEquals(jsonString, json); }
From source file:org.trustedanalytics.metricsprovider.cloudadapter.api.CfSpace.java
@JsonIgnore public UUID getGuid() { Optional<CfSpace> space = Optional.of(this); return space.map(CfSpace::getMetadata).map(CfMetadata::getGuid).orElse(null); }
From source file:org.lendingclub.mercator.aws.S3BucketScanner.java
@Override public Optional<String> computeArn(JsonNode n) { String name = n.get("name").asText(); return Optional.of("arn:aws:s3:::" + name); }
From source file:co.runrightfast.core.utils.ConfigUtils.java
static Optional<Config> getConfig(final Config config, final String path, final String... paths) { if (!hasPath(config, path, paths)) { return Optional.empty(); }//from w ww.j a v a 2s .c om return Optional.of(config.getConfig(configPath(path, paths))); }
From source file:org.openmhealth.shim.jawbone.mapper.JawboneBodyMassIndexDataPointMapper.java
@Override Optional<Measure.Builder<BodyMassIndex, ?>> newMeasureBuilder(JsonNode listEntryNode) { TypedUnitValue<BodyMassIndexUnit> bmiValue = new TypedUnitValue<>(KILOGRAMS_PER_SQUARE_METER, asRequiredDouble(listEntryNode, "bmi")); return Optional.of(new BodyMassIndex.Builder(bmiValue)); }
From source file:ms.dew.devops.kernel.plugin.appkind.frontend_node.FrontendNodePrepareFlow.java
@Override protected Optional<String> getPreparePackageCmd(FinalProjectConfig config, String currentPath) { String cmd = config.getApp().getPreparePackageCmd(); if (cmd == null || cmd.trim().isEmpty()) { // //from ww w. j av a2s . co m cmd = "npm install"; } cmd = "cd " + currentPath + " && " + cmd; return Optional.of(cmd); }
From source file:org.lendingclub.mercator.aws.AMIScanner.java
@Override public Optional<String> computeArn(JsonNode n) { String region = n.path(AWSScanner.AWS_REGION_ATTRIBUTE).asText(null); String imageId = n.path(IMAGE_ID_ATTRIBUTE).asText(null); Preconditions.checkState(!Strings.isNullOrEmpty(region), "aws_region not set"); Preconditions.checkState(!Strings.isNullOrEmpty(imageId), "aws_imageId not set"); return Optional.of(String.format("arn:aws:ec2:%s::image/%s", region, imageId)); }
From source file:com.ikanow.aleph2.example.flume_harvester.utils.FlumeUtils.java
/** Returns the morphlines config * @param bucket_config/*from w w w. j av a 2 s . c om*/ * @return */ public static Optional<String> createMorphlinesConfig(final FlumeBucketConfigBean bucket_config) { //TODO (ALEPH-10): security return Optional.of(Optional.ofNullable(bucket_config.morphlines_config_str())) .map(opt -> opt.map(ss -> ss + "\n").orElse("")) .map(s -> s + Optional.ofNullable(bucket_config.morphlines_config()) .map(o -> _mapper.convertValue(o, JsonNode.class).toString()).orElse("")) .filter(s -> !s.isEmpty()); }
From source file:com.orange.ngsi2.model.ErrorTest.java
@Test public void checkSerializationComplete() throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper().registerModule(new Jdk8Module()); Error parseError = new Error("400"); parseError.setDescription(Optional.of("The incoming JSON payload cannot be parsed")); parseError.setAffectedItems(Optional.of(Collections.singleton("entities"))); String json = objectMapper.writeValueAsString(parseError); assertTrue(json.contains("error")); assertTrue(json.contains("description")); assertTrue(json.contains("affectedItems")); }
From source file:ch.zweivelo.renderer.simple.shapes.Sphere.java
@Override public Optional<Double> calculateIntersectionDistance(final Ray ray) { Vector3D dir = ray.getDirection(); Vector3D tmp = ray.getOrigin().subtract(center); OptionalDouble min = Solver.QUADRATIC .solve(tmp.dotProduct(tmp) - radius * radius, 2 * dir.dotProduct(tmp), dir.dotProduct(dir)).min(); if (min.isPresent()) { return Optional.of(min.getAsDouble()); }/*ww w . j a v a 2 s.c om*/ return Optional.empty(); }