List of usage examples for java.util Optional map
public <U> Optional<U> map(Function<? super T, ? extends U> mapper)
From source file:org.trustedanalytics.cloud.cc.api.CcServiceInstance.java
@JsonIgnore public String getServicePlanName() { Optional<CcServiceInstance> serviceInstance = Optional.of(this); return serviceInstance.map(CcServiceInstance::getServicePlan).map(CcServicePlan::getName).orElse(null); }
From source file:se.omegapoint.facepalm.client.adapters.PolicyAdapter.java
public Policy retrievePolicy(final String filename) { final Optional<se.omegapoint.facepalm.domain.Policy> policy = policyService.retrievePolicy(filename); return policy.map(p -> new Policy(p.text)).orElseGet(() -> new Policy("Could not load policy")); }
From source file:org.trustedanalytics.cloud.cc.api.CcServiceInstance.java
@JsonIgnore public UUID getServiceGuid() { Optional<CcServiceInstance> serviceInstance = Optional.of(this); return serviceInstance.map(CcServiceInstance::getServicePlan).map(CcServicePlan::getService) .map(CcService::getGuid).orElse(null); }
From source file:io.pravega.controller.store.stream.tables.TableHelper.java
/** * Get active segments at given timestamp. * Perform binary search on index table to find the record corresponding to timestamp. * Note: index table may be stale or not reflect lastest state of history table. * So we may need to fall through in the history table from the record being pointed to by index * until we find the correct record./*from w w w. ja v a2 s . c o m*/ * * @param timestamp timestamp * @param indexTable indextable * @param historyTable history table * @return */ public static List<Integer> getActiveSegments(final long timestamp, final byte[] indexTable, final byte[] historyTable) { Optional<HistoryRecord> record = HistoryRecord.readRecord(historyTable, 0, true); if (record.isPresent() && timestamp > record.get().getScaleTime()) { final Optional<IndexRecord> recordOpt = IndexRecord.search(timestamp, indexTable).getValue(); final int startingOffset = recordOpt.isPresent() ? recordOpt.get().getHistoryOffset() : 0; record = findRecordInHistoryTable(startingOffset, timestamp, historyTable, true); } return record.map(HistoryRecord::getSegments).orElse(new ArrayList<>()); }
From source file:fi.helsinki.opintoni.cache.SpringFeedFetcherCache.java
private SyndFeedInfo get(URL feedUrl) { Optional<ValueWrapper> valueWrapper = Optional.ofNullable(cache.get(feedUrl)); return valueWrapper.map(w -> (SyndFeedInfo) w.get()).orElse(null); }
From source file:se.omegapoint.facepalm.client.security.DbAuthenticationProvider.java
@Override public Authentication authenticate(final Authentication authentication) throws AuthenticationException { final UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication; final String username = (String) token.getPrincipal(); final String password = (String) token.getCredentials(); final Optional<User> user = userRepository.findByNameAndPassword(username, password); return user.map( u -> new UsernamePasswordAuthenticationToken(new AuthenticatedUser(u.username), null, emptyList())) .orElse(null);//from w ww . j av a 2 s . c o m }
From source file:io.github.cdelmas.spike.springboot.car.CarsController.java
@RequestMapping(value = "/{id}", method = RequestMethod.GET) public ResponseEntity<CarRepresentation> byId(@PathVariable("id") String carId) { Optional<Car> car = carRepository.byId(Integer.parseInt(carId)); return car.map(c -> { CarRepresentation rep = toCarRepresentation(c); return new ResponseEntity<>(rep, HttpStatus.OK); }).orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND)); }
From source file:com.example.TokenServices.java
@Override public OAuth2AccessToken readAccessToken(final String accessToken) { final Optional<AccessTokenEntity> token = accessTokenRepository.findByAccessToken(accessToken); return token.map(AccessToken::new).orElseThrow(invalidAccessToken(accessToken)); }
From source file:com.example.TokenServices.java
@Override public OAuth2Authentication loadAuthentication(final String accessToken) throws AuthenticationException, InvalidTokenException { final Optional<AccessTokenEntity> token = accessTokenRepository.findByAccessToken(accessToken); return token.map(Authentication::new).map(Optional::of).orElseThrow(invalidAccessToken(accessToken)) .filter(Authentication::isNotExpired).map(Authentication::oauth2) .orElseThrow(tokenIsExpired(accessToken)); }
From source file:com.blackducksoftware.integration.hub.detect.detector.bitbake.GraphParserTransformer.java
private Optional<String> getVersionFromNode(final GraphNode graphNode) { final Optional<String> attribute = getLabelAttribute(graphNode); return attribute.map(this::getVersionFromLabel); }