List of usage examples for java.util Optional isPresent
public boolean isPresent()
From source file:org.openwms.tms.service.TransportationServiceImpl.java
/** * {@inheritDoc}// www.jav a2 s. c om */ @Override public int getNoTransportOrdersToTarget(String target, String... states) { int i = 0; for (TargetResolver<Target> tr : targetResolvers) { Optional<Target> t = tr.resolve(target); if (t.isPresent()) { i = +tr.getHandler().getNoTOToTarget(t.get()); } } return i; }
From source file:org.openmhealth.shim.withings.mapper.WithingsIntradayStepCountDataPointMapper.java
/** * Maps an individual list node from the array in the Withings activity measure endpoint response into a {@link * StepCount} data point.// w w w . j a va 2s.com * * @param nodeWithSteps activity node from the array "activites" contained in the "body" of the endpoint response * @return a {@link DataPoint} object containing a {@link StepCount} measure with the appropriate values from * the JSON node parameter, wrapped as an {@link Optional} */ private Optional<DataPoint<StepCount>> asDataPoint(JsonNode nodeWithSteps, Long startDateTimeInUnixEpochSeconds) { Long stepCountValue = asRequiredLong(nodeWithSteps, "steps"); StepCount.Builder stepCountBuilder = new StepCount.Builder(stepCountValue); Optional<Long> duration = asOptionalLong(nodeWithSteps, "duration"); if (duration.isPresent()) { OffsetDateTime offsetDateTime = OffsetDateTime .ofInstant(Instant.ofEpochSecond(startDateTimeInUnixEpochSeconds), ZoneId.of("Z")); stepCountBuilder.setEffectiveTimeFrame(TimeInterval.ofStartDateTimeAndDuration(offsetDateTime, new DurationUnitValue(DurationUnit.SECOND, duration.get()))); } Optional<String> userComment = asOptionalString(nodeWithSteps, "comment"); if (userComment.isPresent()) { stepCountBuilder.setUserNotes(userComment.get()); } StepCount stepCount = stepCountBuilder.build(); return Optional.of(newDataPoint(stepCount, null, true, null)); }
From source file:com.macrossx.wechat.impl.WechatMenuHelper.java
/** * delete menu/*from ww w . j av a2s. c o m*/ * * @param menu * menu to create * {@link https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141015&token=&lang=zh_CN} * @return true sucess */ public boolean deleteMenu() { try { Optional<WechatAccessToken> token = wechatHelper.getAccessToken(); if (token.isPresent()) { WechatAccessToken accessToken = token.get(); HttpGet httpGet = new HttpGet(); httpGet.setURI(new URI( MessageFormat.format(WechatConstants.MENU_DELETE_URL, accessToken.getAccess_token()))); Optional<WechatResponseObj> response = new WechatHttpClient().send(httpGet, WechatResponseObj.class); if (response.isPresent()) { WechatResponseObj e = response.get(); log.info(e.toString()); if (0 == e.getErrcode()) { return true; } } } } catch (URISyntaxException e) { log.info(e.getMessage()); } return false; }
From source file:org.fcrepo.camel.ldpath.FedoraProvider.java
@Override public List<String> buildRequestUrl(final String resourceUri, final Endpoint endpoint) { LOGGER.debug("Processing: " + resourceUri); Objects.requireNonNull(resourceUri); try {//w ww.j a v a 2 s .c o m final Optional<String> nonRdfSourceDescUri = getNonRDFSourceDescribedByUri(resourceUri); if (nonRdfSourceDescUri.isPresent()) { return Collections.singletonList(nonRdfSourceDescUri.get()); } } catch (IOException ex) { throw new UncheckedIOException(ex); } return Collections.singletonList(resourceUri); }
From source file:com.blackducksoftware.integration.hub.detect.detector.gradle.GradleReportParserTest.java
@Test public void testSpringFrameworkAop() throws IOException { final File file = new File("src/test/resources/gradle/spring-framework/spring_aop_dependencyGraph.txt"); final GradleReportParser gradleReportParser = new GradleReportParser(new ExternalIdFactory()); final Optional<DetectCodeLocation> result = gradleReportParser.parseDependencies(file); assertTrue(result.isPresent()); System.out.println(new GsonBuilder().setPrettyPrinting().create().toJson(result.get())); }
From source file:com.blackducksoftware.integration.hub.detect.detector.gradle.GradleReportParserTest.java
@Test public void testImplementationsGraph() throws IOException { final File file = new File("src/test/resources/gradle/gradle_implementations_dependencyGraph.txt"); final GradleReportParser gradleReportParser = new GradleReportParser(new ExternalIdFactory()); final Optional<DetectCodeLocation> result = gradleReportParser.parseDependencies(file); assertTrue(result.isPresent()); System.out.println(new GsonBuilder().setPrettyPrinting().create().toJson(result.get())); }
From source file:com.devicehive.service.OAuthTokenService.java
@Transactional(propagation = Propagation.REQUIRED) public JwtTokenVO authenticate(@NotNull UserVO user) { UserWithNetworkVO userWithNetwork = userService.findUserWithNetworks(user.getId()); userService.refreshUserLoginData(user); Set<String> networkIds = new HashSet<>(); Set<String> deviceGuids = new HashSet<>(); userWithNetwork.getNetworks().stream().forEach(network -> { networkIds.add(network.getId().toString()); Optional<NetworkWithUsersAndDevicesVO> networkWithDevices = networkDao.findWithUsers(network.getId()); if (networkWithDevices.isPresent()) { networkWithDevices.get().getDevices().stream().forEach(device -> { deviceGuids.add(device.getGuid()); });/* w w w. jav a 2 s .c om*/ } }); JwtTokenVO tokenVO = new JwtTokenVO(); JwtPayload payload = JwtPayload.newBuilder().withUserId(userWithNetwork.getId()) .withActions(new HashSet<>(Arrays.asList(AvailableActions.getClientActions()))) .withNetworkIds(networkIds).withDeviceGuids(deviceGuids).buildPayload(); tokenVO.setAccessToken(tokenService.generateJwtAccessToken(payload)); return tokenVO; }
From source file:io.gravitee.management.service.impl.UserServiceImpl.java
@Override public UserEntity findByName(String username) { try {// ww w .j a va2s . c o m LOGGER.debug("Find user by name: {}", username); Optional<User> user = userRepository.findByUsername(username); if (user.isPresent()) { return convert(user.get()); } throw new UserNotFoundException(username); } catch (TechnicalException ex) { LOGGER.error("An error occurs while trying to find a user using its name {}", username, ex); throw new TechnicalManagementException( "An error occurs while trying to find a user using its name " + username, ex); } }
From source file:org.zalando.riptide.Router.java
final <A> Capture route(final ClientHttpResponse response, final List<HttpMessageConverter<?>> converters, final Selector<A> selector, final Collection<Binding<A>> bindings) { final Optional<A> attribute; try {/*from w ww .jav a 2 s . com*/ attribute = selector.attributeOf(response); } catch (final IOException e) { throw new RestClientException("Unable to retrieve attribute of response", e); } final Map<Optional<A>, Binding<A>> index = bindings.stream() .collect(toMap(Binding::getAttribute, identity(), this::denyDuplicates, LinkedHashMap::new)); final Optional<Binding<A>> match = selector.select(attribute, index); try { if (match.isPresent()) { final Binding<A> binding = match.get(); try { return binding.execute(response, converters); } catch (final NoRouteException e) { return propagateNoMatch(response, converters, index, e); } } else { return routeNone(response, converters, index); } } catch (final IOException e) { throw new RestClientException("Unable to execute binding", e); } }
From source file:com.github.cbismuth.fdupes.io.PathOrganizer.java
private void moveUniqueFiles(final Path destination, final Iterable<PathElement> uniqueElements) { final AtomicInteger counter = new AtomicInteger(1); uniqueElements.forEach(pathElement -> { final Optional<Path> timestampPath = pathAnalyser.getTimestampPath(destination, pathElement.getPath()); if (timestampPath.isPresent()) { onTimestampPath(pathElement, timestampPath.get()); } else {/* w w w. j ava 2 s . c o m*/ onNoTimestampPath(destination, pathElement, counter); } }); }