List of usage examples for java.util Optional get
public T get()
From source file:org.onebusaway.alexa.MainSpeechlet.java
public SpeechletResponse onLaunch(LaunchRequest request, Session session) throws SpeechletException { Optional<ObaUserDataItem> optUserData = obaDao.getUserData(session); if (optUserData.isPresent()) { try {/*from ww w .ja v a 2 s. c o m*/ return getAuthedSpeechlet(optUserData.get()).onLaunch(request, session); } catch (URISyntaxException e) { log.error("Launch exception: " + e.getMessage()); log.error("Backtrace:\n" + e.getStackTrace()); throw new SpeechletException("Error creating user data on Launch using ObaBaseUrl: " + e); } } else { return anonSpeechlet.onLaunch(request, session); } }
From source file:io.dfox.junit.http.JUnitHttpApplication.java
/** * Run the specified function using the context created by the specified path. * * @param path The path to the function/*w w w. j a v a2s . c om*/ * @param func The function to execute using the runner and parsed path * @return The runner Summary * @throws InvalidPathException If the path is invalid */ public Summary run(final String path, final BiFunction<JUnitHttpRunner, Path, Summary> func) throws InvalidPathException { final Optional<Path> maybePath = Path.parse(path); if (maybePath.isPresent()) { Path testPath = maybePath.get(); final JUnitHttpRunner runner = getRunner(testPath); return func.apply(runner, testPath); } else { throw new InvalidPathException(path); } }
From source file:com.epam.ta.reportportal.ws.resolver.ActiveUserWebArgumentResolver.java
@Override public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer paramModelAndViewContainer, NativeWebRequest webRequest, WebDataBinderFactory paramWebDataBinderFactory) throws Exception { Authentication authentication = (Authentication) webRequest.getUserPrincipal(); if (!authentication.getAuthorities().isEmpty()) { Optional<UserRole> userRole = UserRole .findByAuthority(authentication.getAuthorities().iterator().next().getAuthority()); return userRole.isPresent() ? userRole.get() : WebArgumentResolver.UNRESOLVED; }/*from ww w . j av a2 s.c o m*/ return WebArgumentResolver.UNRESOLVED; }
From source file:ddf.catalog.validation.impl.SizeValidatorTest.java
private void validateWithErrors(final Attribute attribute, final long min, final long max, final int expectedErrors) { final Optional<AttributeValidationReport> reportOptional = getReportOptional(attribute, min, max); assertThat(reportOptional.get().getAttributeValidationViolations(), hasSize(expectedErrors)); }
From source file:org.ulyssis.ipp.snapshot.CorrectionEvent.java
protected Snapshot doApply(Snapshot snapshot) { TeamStates oldTeamStates = snapshot.getTeamStates(); Optional<TeamState> oldTeamState = oldTeamStates.getStateForTeam(teamNb); TeamState newTeamState;// ww w . j a v a2 s. c om if (oldTeamState.isPresent()) { newTeamState = oldTeamState.get().addCorrection(correction); } else { newTeamState = new TeamState().addCorrection(correction); } return Snapshot.builder(getTime(), snapshot) .withTeamStates(snapshot.getTeamStates().setStateForTeam(teamNb, newTeamState)).build(); }
From source file:com.antonjohansson.managementcenter.core.web.VaadinResourcesServlet.java
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name = getRequestURI(request); Optional<URL> resource = getResource(name); if (!resource.isPresent()) { response.sendError(SC_NOT_FOUND); return;/* w ww. j a va 2 s . c o m*/ } try (InputStream input = resource.get().openStream(); OutputStream output = response.getOutputStream()) { copy(input, output); } }
From source file:org.openmhealth.shim.misfit.mapper.MisfitPhysicalActivityDataPointMapper.java
@Override public Optional<DataPoint<PhysicalActivity>> asDataPoint(JsonNode sessionNode) { checkNotNull(sessionNode);//ww w . j a v a 2s. 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:it.tidalwave.bluemarine2.metadata.impl.audio.musicbrainz.MusicBrainzAudioMedatataImporter.java
/******************************************************************************************************************* * * FIXME: DUPLICATED FROM EmbbededAudioMetadataImporter * ******************************************************************************************************************/ @Nonnull//w w w . j a va 2s. c o m private static IRI recordIriOf(final @Nonnull Metadata metadata, final @Nonnull String recordTitle) { final Optional<Cddb> cddb = metadata.get(CDDB); return BMMO.recordIriFor((cddb.isPresent()) ? createSha1IdNew(cddb.get().getToc()) : createSha1IdNew("RECORD:" + recordTitle)); }
From source file:de.sainth.recipe.backend.rest.controller.LogoutController.java
@RequestMapping() @ResponseStatus(HttpStatus.NO_CONTENT)/*from ww w . j a va2 s .c o m*/ void logout(HttpServletRequest request, HttpServletResponse response) { if ("/logout".equals(request.getServletPath())) { Optional<Cookie> cookie = Arrays.stream(request.getCookies()) .filter(c -> "recipe_bearer".equals(c.getName())).findFirst(); if (cookie.isPresent()) { Cookie c = cookie.get(); c.setValue(""); c.setPath("/"); c.setMaxAge(0); response.addCookie(c); } response.setStatus(HttpServletResponse.SC_NO_CONTENT); } }
From source file:se.omegapoint.facepalm.application.FriendService.java
public void addFriend(final String username, final String friendUsername) { notBlank(username);/*from ww w . jav a2 s . co m*/ notBlank(friendUsername); final Optional<User> user = getUser(username); final Optional<User> friend = getUser(friendUsername); if (user.isPresent() && friend.isPresent()) { userRepository.addFriend(user.get().username, friend.get().username); } }