List of usage examples for java.util Optional isPresent
public boolean isPresent()
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.obiba.mica.micaConfig.rest.EntityConfigResource.java
@GET @Path("/form-custom") public U getComplete(@Context UriInfo uriInfo) { Optional<T> optionalConfig = getConfigService().findPartial(); if (!optionalConfig.isPresent()) throw NoSuchEntityException.withPath(EntityConfig.class, uriInfo.getPath()); return asDto(optionalConfig.get()); }
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:it.polimi.diceH2020.launcher.service.Validator.java
public boolean validateJobProfile(Path pathToFile) { Optional<JobProfilesMap> sol = objectFromPath(pathToFile, JobProfilesMap.class); return (sol.isPresent() && sol.get().validate()); }
From source file:org.openmhealth.shim.fitbit.mapper.FitbitIntradayStepCountDataPointMapper.java
@Override protected Optional<DataPoint<StepCount>> asDataPoint(JsonNode listEntryNode) { BigDecimal stepCountValue = asRequiredBigDecimal(listEntryNode, "value"); if (stepCountValue.intValue() == 0) { return Optional.empty(); }//from w w w . j a v a 2 s . c om StepCount.Builder stepCountBuilder = new StepCount.Builder(stepCountValue); Optional<LocalDate> dateFromParent = getDateFromSummaryForDay(); if (dateFromParent.isPresent()) { // Set the effective time frame only if we have access to the date and time asOptionalString(listEntryNode, "time").ifPresent(time -> stepCountBuilder.setEffectiveTimeFrame( ofStartDateTimeAndDuration(dateFromParent.get().atTime(LocalTime.parse(time)).atOffset(UTC), new DurationUnitValue(MINUTE, 1)))); // We use 1 minute since the shim requests data at 1 minute granularity } return Optional.of(newDataPoint(stepCountBuilder.build(), null)); }
From source file:com.carlomicieli.jtrains.test.ValidationResult.java
private boolean exists(Predicate<ConstraintViolation<T>> p) { Optional<ConstraintViolation<T>> err = errorsStream().filter(p).findAny(); return err.isPresent(); }
From source file:fi.helsinki.opintoni.security.CustomAuthenticationSuccessHandler.java
private void syncUserWithDatabase(AppUser appUser) { Optional<User> user = getUserFromDb(appUser); if (user.isPresent()) { updateExistingUser(appUser, user.get()); } else {//ww w .jav a 2s. c om createNewUser(appUser); } }
From source file:org.openmhealth.dsu.repository.EndUserRepositoryIntegrationTests.java
@Test public void findOneShouldReturnSavedUser() { EndUser expected = endUserRepository.save(newUser()); Optional<EndUser> actual = endUserRepository.findOne(TEST_USERNAME); assertThat(actual.isPresent(), equalTo(true)); assertThat(actual.get(), equalTo(expected)); }
From source file:pitayaa.nail.msg.core.account.controller.AccountLicenseController.java
@RequestMapping(value = "/accountsLicense/{ID}", method = RequestMethod.GET) public @ResponseBody ResponseEntity<?> findOneAccLicense(@PathVariable("ID") UUID uid) throws Exception { Optional<AccountLicense> accountLicense = accLicenseService.findOne(uid); if (!accountLicense.isPresent()) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } else {/* w w w. j a va 2 s. c om*/ return new ResponseEntity<>(accountLicense, HttpStatus.OK); } }
From source file:org.openmhealth.shim.runkeeper.mapper.RunkeeperCaloriesBurnedDataPointMapper.java
private Optional<CaloriesBurned> getMeasure(JsonNode itemNode) { Optional<Double> calorieValue = asOptionalDouble(itemNode, "total_calories"); if (!calorieValue.isPresent()) { // Not all activity datapoints have the "total_calories" property return Optional.empty(); }// w w w . j ava 2 s.com CaloriesBurned.Builder caloriesBurnedBuilder = new CaloriesBurned.Builder( new KcalUnitValue(KcalUnit.KILOCALORIE, calorieValue.get())); setEffectiveTimeFrameIfPresent(itemNode, caloriesBurnedBuilder); Optional<String> activityType = asOptionalString(itemNode, "type"); activityType.ifPresent(at -> caloriesBurnedBuilder.setActivityName(at)); return Optional.of(caloriesBurnedBuilder.build()); }