List of usage examples for java.util Optional ofNullable
@SuppressWarnings("unchecked") public static <T> Optional<T> ofNullable(T value)
From source file:fi.helsinki.opintoni.web.controller.RedirectController.java
private String getRedirectPath(String configurationParam, String defaultRedirect) { return Optional.ofNullable(appConfiguration.get(configurationParam)).filter(p -> p.length() > 0) .orElseGet(() -> defaultRedirect); }
From source file:io.mapzone.arena.csw.catalog.CswMetadataBase.java
@Override public Optional<String> getType() { return Optional.ofNullable(record().type); }
From source file:com.culturedear.chord.ChordAnalyzerController.java
@RequestMapping("/analyze") public ResponseEntity<Object> identifyChordByNotes(@RequestParam(value = "notes") String notes) { Chord jfugueChord = null;/* w w w . j a v a 2 s .c om*/ musicChord = null; try { jfugueChord = Chord.fromNotes(notes); musicChord = new MusicChord(Note.getToneStringWithoutOctave(jfugueChord.getRoot().getValue()), jfugueChord.getChordType().toLowerCase(), Note.getToneStringWithoutOctave(jfugueChord.getBassNote().getValue()), jfugueChord.getInversion(), jfugueChord.isMajor(), jfugueChord.isMinor(), jfugueChord.toString()); } catch (Exception e) { System.out.println("Exception encountered in ChordAnalyzerController#identifyChordByNotes: " + e); } return Optional.ofNullable(musicChord).map(mc -> new ResponseEntity<>((Object) mc, HttpStatus.OK)) .orElse(new ResponseEntity<>("Could not analyze the chord", HttpStatus.INTERNAL_SERVER_ERROR)); }
From source file:com.lithium.flow.shell.sshj.SshjExec.java
@Override @Nonnull// w w w . j ava 2s. c o m public Optional<Integer> exit() throws IOException { out().count(); err().count(); Integer status = command.getExitStatus(); close(); return Optional.ofNullable(status); }
From source file:io.github.carlomicieli.footballdb.starter.parsers.SeasonGamesParser.java
private Optional<Element> gamesTable(Document doc) { return Optional.ofNullable(doc.getElementById("games")); }
From source file:com.greglturnquist.HomeController.java
private static String currentUser(Object auth) { return Optional.ofNullable(auth).map(authentication -> authentication.toString()).orElse("Unknown user"); }
From source file:enmasse.controller.flavor.FlavorManager.java
@Override public Optional<Flavor> getFlavor(String flavorName) { return Optional.ofNullable(flavorMap.get(flavorName)); }
From source file:com.epam.ta.reportportal.demo_data.DemoDataService.java
DemoDataRs generate(DemoDataRq rq, String projectName, String user) { DemoDataRs demoDataRs = new DemoDataRs(); Project project = projectRepository.findOne(projectName); StatisticsCalculationStrategy statsStrategy = Optional .ofNullable(project.getConfiguration().getStatisticsCalculationStrategy()) .orElse(StatisticsCalculationStrategy.STEP_BASED); BusinessRule.expect(project, Predicates.notNull()).verify(ErrorType.PROJECT_NOT_FOUND, projectName); final List<String> launches = demoLaunchesService.generateDemoLaunches(rq, user, projectName, statsStrategy);//w w w. j av a 2 s .c o m demoDataRs.setLaunches(launches); if (rq.isCreateDashboard()) { Dashboard demoDashboard = demoDashboardsService.generate(rq, user, projectName); demoDataRs.setDashboards(Collections.singletonList(demoDashboard.getId())); } return demoDataRs; }
From source file:com.netflix.genie.common.internal.dto.v4.CommonRequestImpl.java
/** * {@inheritDoc} */ @Override public Optional<String> getRequestedId() { return Optional.ofNullable(this.requestedId); }
From source file:com.devicehive.websockets.handlers.DeviceHandlers.java
@PreAuthorize("isAuthenticated()") public WebSocketResponse processDeviceGet(JsonObject request) { final String deviceId = Optional.ofNullable(request.get(Constants.DEVICE_ID)).map(JsonElement::getAsString) .orElse(null);//from w ww .jav a 2 s .c o m HivePrincipal principal = (HivePrincipal) SecurityContextHolder.getContext().getAuthentication() .getPrincipal(); WebSocketResponse response = new WebSocketResponse(); if (deviceId != null) { DeviceVO toResponse = deviceService.findByGuidWithPermissionsCheck(deviceId, principal); response.addValue(Constants.DEVICE, toResponse, DEVICE_PUBLISHED); return response; } else { for (String device : principal.getDeviceGuids()) { DeviceVO toResponse = deviceService.findByGuidWithPermissionsCheck(device, principal); response.addValue(Constants.DEVICE, toResponse, DEVICE_PUBLISHED); } return response; } }