List of usage examples for java.util Optional get
public T get()
From source file:ch.zweivelo.renderer.simple.shapes.PlaneTest.java
@Test public void testIntersect() throws Exception { Optional<CollisionInformation> collisionInformationOptional = plane.intersect(ray); CollisionInformation collisionInformation = collisionInformationOptional.get(); assertNotNull(collisionInformation.getShape()); assertTrue(collisionInformation.getShape() instanceof Plane); }
From source file:org.jhk.pulsing.web.service.prod.UserService.java
@Override public Result<User> validateUser(String email, String password) { Optional<User> user = mySqlUserDao.validateUser(email, password); return user.isPresent() ? new Result<>(SUCCESS, user.get()) : new Result<>(FAILURE, "Failed in validating " + email + " : " + password); }
From source file:com.formkiq.core.form.bean.CustomConvertUtilsBean.java
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override//from w w w . j a va2 s .c om public Object convert(final String value, final Class clazz) { if (clazz.isEnum()) { String val = Strings.extractLabelAndValue(value).getRight(); try { Method method = clazz.getMethod("find", String.class); Object result = method.invoke(method, val); if (result instanceof Optional) { Optional<Object> op = (Optional<Object>) result; if (op.isPresent()) { return op.get(); } } } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { // ignore error } return Enum.valueOf(clazz, val); } return super.convert(value, clazz); }
From source file:com.fredhopper.connector.query.populators.response.SearchResponseSpellingSuggestionPopulator.java
@Override public void populate(final FhSearchResponse source, final ProductSearchPageData<FhSearchQueryData, I> target) { final Optional<Universe> universe = getUniverse(source); if (universe.isPresent()) { final QueryAlternatives alternatives = universe.get().getQueryAlternatives(); if (alternatives != null && alternatives.isWasExecuted() && CollectionUtils.isNotEmpty(alternatives.getQuerySuggestion())) { final QuerySuggestion querySuggestion = alternatives.getQuerySuggestion().get(0); final SpellingSuggestionData<FhSearchQueryData> spellingSuggestionData = new SpellingSuggestionData<>(); spellingSuggestionData.setSuggestion(querySuggestion.getValue().getValue()); final FhSearchQueryData correctedQuery = cloneSearchQueryData(target.getCurrentQuery()); correctedQuery.setFreeTextSearch(querySuggestion.getValue().getValue()); correctedQuery.setLocation(querySuggestion.getUrlParams()); spellingSuggestionData.setQuery(correctedQuery); target.setSpellingSuggestion(spellingSuggestionData); }/* w w w .j a v a2s.c om*/ } }
From source file:controller.LeerlingController.java
@RequestMapping(method = RequestMethod.GET) public String doGet(@RequestParam("klasNaam") String klasNaam, Model model) { final String klNaam = klasNaam; Optional<Klas> klas = klasManager.getItems().stream().filter(k -> k.getNaam().equals(klNaam)).findFirst(); if (klas.isPresent()) { Klas k = klas.get(); List<Leerling> leerlingen = k.getLeerlingen(); model.addAttribute("klasNaam", k.getNaam()); model.addAttribute("leerlingen", leerlingen); return "leerlingOverview"; } else {//ww w . j av a2 s . co m return "redirect:/klas"; } }
From source file:com.amazonaws.serverless.sample.spring.PetsController.java
@RequestMapping(path = "/pets", method = RequestMethod.GET) public Pet[] listPets(@RequestParam("limit") Optional<Integer> limit) { int queryLimit = 10; if (limit.isPresent()) { queryLimit = limit.get(); }//from w w w . ja va 2 s.c o m Pet[] outputPets = new Pet[queryLimit]; for (int i = 0; i < queryLimit; i++) { Pet newPet = new Pet(); newPet.setId(UUID.randomUUID().toString()); newPet.setName(PetData.getRandomName()); newPet.setBreed(PetData.getRandomBreed()); newPet.setDateOfBirth(PetData.getRandomDoB()); outputPets[i] = newPet; } return outputPets; }
From source file:io.github.retz.scheduler.AdminConsoleTest.java
@Before public void before() throws Exception { InputStream in = Launcher.class.getResourceAsStream("/retz-tls.properties"); ServerConfiguration config = new ServerConfiguration(in); Database.getInstance().init(config); Optional<JmxServer> server = AdminConsole.startJmxServer(config); port = config.getJmxPort();/*from www .j av a2s .co m*/ jmxServer = server.get(); }
From source file:example.springdata.cassandra.java8.Java8IntegrationTests.java
@Test public void invokesDefaultMethod() { Person homer = repository.save(new Person("1", "Homer", "Simpson")); Optional<Person> result = repository.findByPerson(homer); assertThat(result.isPresent(), is(true)); assertThat(result.get(), is(homer)); }
From source file:org.jhk.pulsing.web.service.prod.UserService.java
@Override public Result<User> getUser(UserId userId) { Result<User> result = new Result<>(FAILURE, "Unable to find " + userId); Optional<User> user = mySqlUserDao.getUser(userId); if (user.isPresent()) { result = new Result<>(SUCCESS, user.get()); }/* www . j av a 2s . c o m*/ return result; }
From source file:org.openmhealth.shim.fitbit.mapper.FitbitBodyWeightDataPointMapper.java
@Override protected Optional<DataPoint<BodyWeight>> asDataPoint(JsonNode node) { MassUnitValue bodyWeight = new MassUnitValue(KILOGRAM, asRequiredDouble(node, "weight")); BodyWeight.Builder builder = new BodyWeight.Builder(bodyWeight); Optional<OffsetDateTime> dateTime = combineDateTimeAndTimezone(node); if (dateTime.isPresent()) { builder.setEffectiveTimeFrame(dateTime.get()); }/* w ww . j a v a 2s . co m*/ Optional<Long> externalId = asOptionalLong(node, "logId"); return Optional.of(newDataPoint(builder.build(), externalId.orElse(null))); }