List of usage examples for java.util Optional ofNullable
@SuppressWarnings("unchecked") public static <T> Optional<T> ofNullable(T value)
From source file:me.adaptive.core.data.api.UserEntityService.java
public Optional<UserEntity> findOne(Long id) { return Optional.ofNullable(userRepository.findOne(id)); }
From source file:org.zalando.riptide.ContentTypeSelector.java
@Override public Optional<MediaType> attributeOf(final ClientHttpResponse response) { return Optional.ofNullable(response.getHeaders().getContentType()); }
From source file:alfio.controller.support.SessionUtil.java
public static Optional<String> retrieveSpecialPriceSessionId(HttpServletRequest request) { return Optional.ofNullable((String) request.getSession().getAttribute(SPECIAL_PRICE_CODE_SESSION_ID)); }
From source file:com.netflix.spinnaker.clouddriver.artifacts.config.BasicAuth.java
default Optional<String> getBasicAuthHeader() { String usernamePassword = null; if (StringUtils.isNotEmpty(getUsernamePasswordFile())) { usernamePassword = CredentialReader.credentialsFromFile(getUsernamePasswordFile()); } else if (StringUtils.isNotEmpty(getUsername()) && StringUtils.isNotEmpty(getPassword())) { usernamePassword = getUsername() + ":" + getPassword(); }//from w w w .j a v a2 s . c o m return Optional.ofNullable(usernamePassword).map(s -> "Basic " + Base64.encodeBase64String(s.getBytes())); }
From source file:com.largecode.interview.rustem.service.UsersServiceImpl.java
@Override public Optional<User> getUserById(long id) { LOGGER.debug("Getting user={}", id); return Optional.ofNullable(userRepository.findOne(id)); }
From source file:edu.jhu.hlt.concrete.ingesters.alnc.ALNCIngester.java
public ALNCIngester(Path path) throws IngestException { this.ts = Timing.currentLocalTime(); this.path = path; try {/*from w w w. j ava 2 s . c om*/ Optional<String> inferredType = Optional.ofNullable(Files.probeContentType(this.path)); String ft = inferredType.orElse("unk"); if (ft.contains("bzip")) this.conv = new ALNCFileConverter(new BZip2CompressorInputStream(Files.newInputStream(this.path))); else this.conv = new ALNCFileConverter(Files.newInputStream(this.path)); } catch (IOException e) { throw new IngestException(e); } }
From source file:org.wallerlab.yoink.service.request.JmsRequestReader.java
@Override public String read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException { while (jmsResquestReaderServiceRunning) { item = Optional.ofNullable(jmsItemReader.read()); if (!item.isPresent()) { Thread.sleep(1000);/*from w w w . ja v a2 s . c o m*/ } else break; } return item.get(); }
From source file:com.create.batch.processor.TicketUpdateItemProcessor.java
@Override public Ticket process(final Ticket item) throws Exception { log.debug("processing : {}", item); final Ticket ticket = Optional.ofNullable(ticketRepository.findByTag(item.getTag())).map(i -> { i.setContent(item.getContent()); return i; }).orElse(item);/* ww w . j av a 2s. co m*/ log.debug("using : {}", ticket); return ticket; }
From source file:com.arpnetworking.configuration.jackson.BaseJsonNodeSource.java
/** * Find the <code>JsonNode</code> if one exists from a specified root node * given a sequence of keys to look-up./*from w w w . j ava 2s . c o m*/ * * @param node The root <code>JsonNode</code>. * @param keys The sequence of keys to search for. * @return The <code>Optional</code> <code>JsonNode</code> instance. */ protected static Optional<JsonNode> getValue(final Optional<JsonNode> node, final String... keys) { JsonNode jsonNode = node.orElse(null); for (final String key : keys) { if (jsonNode == null) { break; } jsonNode = jsonNode.get(key); } return Optional.ofNullable(jsonNode); }
From source file:nl.knaw.huygens.alexandria.endpoint.annotation.AnnotationPrototype.java
public Optional<String> getType() { return Optional.ofNullable(type); }