List of usage examples for java.util Optional of
public static <T> Optional<T> of(T value)
From source file:org.openmhealth.shim.jawbone.mapper.JawboneBodyEventsDataPointMapper.java
/** * Handles some of the basic measure creation activities for body event datapoints and then delegates the creation * of the {@link Builder} to subclasses for each individual body event {@link Measure}. * * @param listEntryNode an individual entry node from the "items" array of a Jawbone endpoint response *//*from ww w .j av a 2 s . c o m*/ @Override protected Optional<T> getMeasure(JsonNode listEntryNode) { if (!containsType(listEntryNode, getBodyEventType())) { return Optional.empty(); } Optional<Measure.Builder<T, ?>> builderOptional = newMeasureBuilder(listEntryNode); if (!builderOptional.isPresent()) { return Optional.empty(); } Measure.Builder<T, ?> builder = builderOptional.get(); setEffectiveTimeFrame(builder, listEntryNode); Optional<String> optionalUserNote = asOptionalString(listEntryNode, "note"); optionalUserNote.ifPresent(builder::setUserNotes); return Optional.of(builder.build()); }
From source file:co.runrightfast.component.events.impl.ComponentEventFactoryImpl.java
@Override public <DATA> ComponentEvent<DATA> componentEvent(@NonNull final Event<DATA> event, @NonNull final Class<DATA> eventDataType, @NonNull final DATA data, @NonNull final String... tags) { final ComponentEventImpl.ComponentEventImplBuilder<DATA> builder = ComponentEventImpl.<DATA>builder() .componentId(componentId).event(event).data(Optional.of(data)); if (ArrayUtils.isNotEmpty(tags)) { return builder.tags(Optional.of(ImmutableSet.copyOf(tags))).build(); }//from w ww .j av a 2 s. co m return builder.build(); }
From source file:com.orange.ngsi2.utility.Utils.java
static public List<Entity> createListEntitiesWrongSyntax() { List<Entity> entities = new ArrayList<Entity>(); Entity entityRoomDC = new Entity("DC_S1 D41", "Room"); entityRoomDC.setAttributes("temperature", new Attribute(35.6)); entities.add(entityRoomDC);/*from w w w . j a v a2 s .c om*/ 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:org.openmhealth.shim.googlefit.mapper.GoogleFitCaloriesBurnedDataPointMapper.java
@Override protected Optional<DataPoint<CaloriesBurned>> asDataPoint(JsonNode listNode) { JsonNode listValueNode = asRequiredNode(listNode, "value"); // TODO isn't this just "value.fpVal"? double caloriesBurnedValue = asRequiredDouble(listValueNode.get(0), "fpVal"); CaloriesBurned.Builder caloriesBurnedBuilder = new CaloriesBurned.Builder( new KcalUnitValue(KILOCALORIE, caloriesBurnedValue)); setEffectiveTimeFrameIfPresent(caloriesBurnedBuilder, listNode); CaloriesBurned caloriesBurned = caloriesBurnedBuilder.build(); Optional<String> originDataSourceId = asOptionalString(listNode, "originDataSourceId"); // Google Fit calories burned endpoint returns calories burned by basal metabolic rate (BMR), however these // are not activity related calories burned so we do not create a datapoint for values from this source if (originDataSourceId.isPresent()) { if (originDataSourceId.get().contains("bmr")) { return Optional.empty(); }/*from w w w. jav a2s . co m*/ } return Optional.of(newDataPoint(caloriesBurned, originDataSourceId.orElse(null))); }
From source file:de.tu_dortmund.ub.data.util.TPUUtil.java
public static Optional<String> getStringConfigValue(final String configKey, final Properties config) { final String configValue = config.getProperty(configKey); final Optional<String> optionalConfigValue; if (configValue != null && !configValue.trim().isEmpty()) { optionalConfigValue = Optional.of(configValue); } else {// w ww. j av a2 s. co m optionalConfigValue = Optional.empty(); } return optionalConfigValue; }
From source file:com.spotify.apollo.http.server.ApolloRequestHandlerTest.java
@Test public void shouldExtractFirstQueryParameter() throws Exception { assertThat(requestHandler.asApolloRequest(httpServletRequest).parameter("q"), is(Optional.of("abc"))); }
From source file:io.gravitee.gateway.http.core.endpoint.impl.tenant.MultiTenantAwareEndpointLifecycleManagerTest.java
@Test public void shouldNotStartEndpoint_notInTenant() throws Exception { io.gravitee.definition.model.Endpoint endpoint = mock(io.gravitee.definition.model.Endpoint.class); when(gatewayConfiguration.tenant()).thenReturn(Optional.of("asia")); when(endpoint.getTenant()).thenReturn("europe"); when(proxy.getEndpoints()).thenReturn(Collections.singletonList(endpoint)); endpointLifecycleManager.start();// w w w .j a va 2 s . co m verify(applicationContext, never()).getBean(eq(HttpClient.class), any(Endpoint.class)); assertTrue(endpointLifecycleManager.targetByEndpoint().isEmpty()); assertTrue(endpointLifecycleManager.endpoints().isEmpty()); }
From source file:fi.hsl.parkandride.core.domain.prediction.AbstractPredictorTest.java
public void insertUtilization(DateTime timestamp, int spacesAvailable) { Utilization u = new Utilization(); u.facilityId = utilizationKey.facilityId; u.capacityType = utilizationKey.capacityType; u.usage = utilizationKey.usage;// w ww .j a va 2 s .c o m u.timestamp = timestamp; u.spacesAvailable = spacesAvailable; utilizationRepository.insertUtilizations(Collections.singletonList(u)); if (!latestInsertedUtilization.isPresent() || latestInsertedUtilization.get().timestamp.isBefore(timestamp)) { latestInsertedUtilization = Optional.of(u); } }
From source file:com.schnobosoft.semeval.cortical.Util.java
/** * Read a file that contains one score per line, as a SemEval gold {@code .gs} file. Empty lines * are allowed and are read as missing values. * * @param scoresFile the scores file to read * @return a list of optional double values of the same length as the input file. For an empty * line, a {@link Optional#EMPTY} object is added to the output list. * @throws IOException//from w ww .j a v a2 s.c o m */ public static List<Optional> readScoresFile(File scoresFile) throws IOException { if (!scoresFile.getName().startsWith(GS_FILE_PREFIX)) { throw new IllegalArgumentException(scoresFile + " does not match expected pattern."); } LOG.info("Reading scores file " + scoresFile); return Files.lines(scoresFile.toPath()) .map(line -> line.isEmpty() ? Optional.empty() : Optional.of(Double.valueOf(line))) .collect(Collectors.toList()); }
From source file:lumbermill.internal.geospatial.GeoIPTest.java
@Ignore @Test/*from w w w.j av a 2s . c o m*/ public void test_geoip_some_fields() { GeoIP geoIP = GeoIP.Factory.create("client_ip", Optional.of("geoip2"), Optional.of(new File("/tmp/GeoLite2-City.mmdb")), Optional.of(asList("timezone", "location"))); JsonEvent event = Codecs.TEXT_TO_JSON.from("Hello").put("client_ip", "37.139.156.40"); geoIP.decorate(event); JsonNode geoip = event.unsafe().get("geoip2"); assertThat(geoip.get("country_code2")).isNull(); assertThat(geoip.get("country_code3")).isNull(); assertThat(geoip.get("timezone").asText()).isEqualTo("Europe/Stockholm"); assertThat(geoip.get("continent_code")).isNull(); assertThat(geoip.get("continent_name")).isNull(); assertThat(geoip.get("country_name")).isNull(); assertThat(geoip.get("city_name")).isNull(); assertThat(geoip.get("longitude")).isNull(); assertThat(geoip.get("latitude")).isNull(); ArrayNode location = (ArrayNode) geoip.get("location"); assertThat(location.get(0).asDouble()).isEqualTo(13.3333); assertThat(location.get(1).asDouble()).isEqualTo(55.7167); System.out.println(event); }