List of usage examples for java.util Optional ofNullable
@SuppressWarnings("unchecked") public static <T> Optional<T> ofNullable(T value)
From source file:fi.helsinki.opintoni.integration.unisport.UnisportMockClient.java
@Override public Optional<UnisportUser> getUnisportUserByPrincipal(String username) { if (username.equals("opettaja@helsinki.fi")) { return Optional.ofNullable(null); } else {//from w w w . ja v a2 s . c om return Optional.ofNullable(getResponse(userResource, new TypeReference<UnisportUser>() { })); } }
From source file:co.runrightfast.vertx.core.eventbus.MessageHeader.java
public static Optional<String> getFromAddress(@NonNull final Message message) { return Optional.ofNullable(message.headers().get(FROM_ADDRESS.header)); }
From source file:com.fantasy.stataggregator.workers.DataRetriever.java
@Override public JSONObject makeRequest() { WebTarget target = getTarget();// w w w .ja v a2 s . c om Response res = target.request(MediaType.APPLICATION_JSON_TYPE).get(); if (res.getStatus() == Response.Status.OK.getStatusCode()) { String consumable = Optional.ofNullable(res.readEntity(String.class)).orElse(""); if (!consumable.isEmpty()) { JSONObject sched; try { sched = new JSONObject(consumable); return sched; } catch (JSONException ex) { Logger.getLogger(ScheduleRetrieverTask.class.getName()).log(Level.SEVERE, null, ex); } } } return null; }
From source file:fi.helsinki.opintoni.config.AppConfiguration.java
public String get(String key) { return Optional.ofNullable(runtimePropertyOverrides.get(key)).orElseGet(() -> environment.getProperty(key)); }
From source file:com.teradata.benchto.driver.graphite.GraphiteProperties.java
public Optional<String> getMemoryGraphiteExpr() { return Optional.ofNullable(memoryGraphiteExpr); }
From source file:fi.helsinki.opintoni.integration.feed.FeedMockClient.java
@Override public Optional<SyndFeed> getFeed(String feedUrl) { Optional<SyndFeed> feed = Optional.empty(); try {//from w ww . j a va 2 s .co m SyndFeedInput input = new SyndFeedInput(); feed = Optional.ofNullable(input.build(new XmlReader(mockFeed.getInputStream()))); } catch (Exception e) { } return feed; }
From source file:com.kazuki43zoo.jpetstore.service.AccountService.java
@Transactional public void updateAccount(Account account, String newPassword) { accountMapper.updateAccount(account); accountMapper.updateProfile(account); Optional.ofNullable(newPassword).ifPresent(x -> { account.setPassword(passwordEncoder.encode(x)); accountMapper.updateSignon(account); });// w w w . ja v a2 s . com }
From source file:cn.edu.zjnu.acm.judge.service.LanguageService.java
public Language getAvailableLanguage(int languageId) { return Optional.ofNullable(languageMapper.findOne(languageId)) .orElseThrow(() -> new NoSuchLanguageException("no such language " + languageId)); }
From source file:com.adobe.acs.commons.models.injectors.annotation.impl.JsonValueMapValueAnnotationProcessorFactory.java
@Override public InjectAnnotationProcessor2 createAnnotationProcessor(AnnotatedElement element) { return Optional.ofNullable(element.getAnnotation(JsonValueMapValue.class)) .map(JsonValueMapValueAnnotationProcessorFactory.InjectAnnotationProcessor2::new).orElse(null); }
From source file:io.gravitee.repository.jdbc.JdbcPageRepository.java
public Optional<Page> findByName(String name) throws TechnicalException { return Optional.ofNullable(pageJpaConverter.convertTo(internalJpaPageRepository.findOne(name))); }