List of usage examples for java.util Optional orElse
public T orElse(T other)
From source file:org.apache.metron.common.configuration.profiler.ProfilerConfig.java
public void setTimestampField(Optional<String> timestampField) { this.timestampField = timestampField.orElse(null); }
From source file:org.apache.metron.common.configuration.profiler.ProfilerConfig.java
public ProfilerConfig withTimestampField(Optional<String> timestampField) { this.timestampField = timestampField.orElse(null); return this; }
From source file:ch.ralscha.extdirectspring.provider.RemoteProviderMetadata.java
@ExtDirectMethod(value = ExtDirectMethodType.STORE_READ, group = "metadata") public ExtDirectStoreResult<Row> method6(ExtDirectStoreReadRequest request, Locale locale, @MetadataParam Optional<Integer> id) { Integer i = id.orElse(20); assertThat(request.getParams().isEmpty()).isTrue(); if (!i.equals(20)) { assertThat(i).isEqualTo(10);/* w w w .ja v a 2s.com*/ } else { assertThat(i).isEqualTo(20); } assertThat(locale).isEqualTo(Locale.ENGLISH); return RemoteProviderStoreRead.createExtDirectStoreResult(request, ":" + i + ";" + locale); }
From source file:com.carlomicieli.jtrains.infrastructure.mongo.JongoRepositoryTests.java
@Test public void shouldFindOneDocumentById() { Optional<MyObj> result = repo(jongo()).findById(objectId("507c7f79bcf86cd7994f6c0e")); assertThat(result.orElse(null)).isNotNull(); }
From source file:com.carlomicieli.jtrains.infrastructure.mongo.JongoRepositoryTests.java
@Test public void shouldFindOneDocument() { Optional<MyObj> result = repo(jongo()).findOne(myObjs -> myObjs.findOne("{'value': 2}")); assertThat(result.orElse(null)).isNotNull(); }
From source file:org.trustedanalytics.metadata.utils.ContentDetectionUtils.java
public static String bestGuessFileType(BufferedInputStream bin, String fileUri) throws IOException { Optional<MediaType> detectedType; String fileExtension = getFileTypeFromExtension(fileUri); LOGGER.info("File extension : " + fileExtension); if (isMeaningfulExtension(fileExtension)) { detectedType = MediaType.fromExtension(fileExtension); LOGGER.info("Media type from extension:" + detectedType); if (!detectedType.isPresent()) { // If we are here, it means there is a meaningful file extension, // but's not supported by our MediaType enum. LOGGER.info("Using new file type:" + fileExtension); return fileExtension; }// w ww . ja v a 2 s .c o m } else { LOGGER.info("Stream type guessing begins.."); detectedType = guessContentFromStream(bin); } LOGGER.info("File type detected: " + detectedType); if (!detectedType.isPresent()) { LOGGER.info("Unable to detect format from extension or content. Assuming CSV type.."); } return detectedType.orElse(MediaType.CSV).getHumanFriendlyFormat(); }
From source file:org.apache.nifi.xml.inference.XmlSchemaInference.java
private DataType inferTextualDataType(final String text) { if (text == null || text.isEmpty()) { return null; }// ww w . ja v a 2 s . c om if (NumberUtils.isParsable(text)) { if (text.contains(".")) { try { final double doubleValue = Double.parseDouble(text); if (doubleValue > Float.MAX_VALUE || doubleValue < Float.MIN_VALUE) { return RecordFieldType.DOUBLE.getDataType(); } return RecordFieldType.FLOAT.getDataType(); } catch (final NumberFormatException nfe) { return RecordFieldType.STRING.getDataType(); } } try { final long longValue = Long.parseLong(text); if (longValue > Integer.MAX_VALUE || longValue < Integer.MIN_VALUE) { return RecordFieldType.LONG.getDataType(); } return RecordFieldType.INT.getDataType(); } catch (final NumberFormatException nfe) { return RecordFieldType.STRING.getDataType(); } } if (text.equalsIgnoreCase("true") || text.equalsIgnoreCase("false")) { return RecordFieldType.BOOLEAN.getDataType(); } final Optional<DataType> timeDataType = timeValueInference.getDataType(text); return timeDataType.orElse(RecordFieldType.STRING.getDataType()); }
From source file:org.openmhealth.shim.misfit.mapper.MisfitPhysicalActivityDataPointMapper.java
@Override public Optional<DataPoint<PhysicalActivity>> asDataPoint(JsonNode sessionNode) { checkNotNull(sessionNode);/* w ww .ja v a 2 s . c om*/ String activityName = asRequiredString(sessionNode, "activityType"); PhysicalActivity.Builder builder = new PhysicalActivity.Builder(activityName); Optional<Double> distance = asOptionalDouble(sessionNode, "distance"); if (distance.isPresent()) { builder.setDistance(new LengthUnitValue(MILE, distance.get())); } Optional<OffsetDateTime> startDateTime = asOptionalOffsetDateTime(sessionNode, "startTime"); Optional<Double> durationInSec = asOptionalDouble(sessionNode, "duration"); if (startDateTime.isPresent() && durationInSec.isPresent()) { DurationUnitValue durationUnitValue = new DurationUnitValue(SECOND, durationInSec.get()); builder.setEffectiveTimeFrame(ofStartDateTimeAndDuration(startDateTime.get(), durationUnitValue)); } asOptionalBigDecimal(sessionNode, "calories") .ifPresent(calories -> builder.setCaloriesBurned(new KcalUnitValue(KILOCALORIE, 96.8))); PhysicalActivity measure = builder.build(); Optional<String> externalId = asOptionalString(sessionNode, "id"); return Optional.of(newDataPoint(measure, RESOURCE_API_SOURCE_NAME, externalId.orElse(null), null)); }
From source file:example.springdata.rest.stores.web.StoresController.java
/** * Looks up the stores in the given distance around the given location. * /*from ww w . ja v a 2s . c om*/ * @param model the {@link Model} to populate. * @param location the optional location, if none is given, no search results will be returned. * @param distance the distance to use, if none is given the {@link #DEFAULT_DISTANCE} is used. * @param pageable the pagination information * @return */ @RequestMapping(value = "/", method = RequestMethod.GET) String index(Model model, @RequestParam Optional<Point> location, @RequestParam Optional<Distance> distance, Pageable pageable) { Point point = location.orElse(KNOWN_LOCATIONS.get("Timesquare NY")); Page<Store> stores = repository.findByAddressLocationNear(point, distance.orElse(DEFAULT_DISTANCE), pageable); model.addAttribute("stores", stores); model.addAttribute("distances", DISTANCES); model.addAttribute("selectedDistance", distance.orElse(DEFAULT_DISTANCE)); model.addAttribute("location", point); model.addAttribute("locations", KNOWN_LOCATIONS); model.addAttribute("api", entityLinks.linkToSearchResource(Store.class, "by-location", pageable).getHref()); return "index"; }
From source file:com.netflix.spinnaker.clouddriver.controllers.ArtifactController.java
@Autowired public ArtifactController(Optional<ArtifactCredentialsRepository> artifactCredentialsRepository, Optional<ArtifactDownloader> artifactDownloader) { this.artifactCredentialsRepository = artifactCredentialsRepository.orElse(null); this.artifactDownloader = artifactDownloader.orElse(null); }