List of usage examples for java.util Optional of
public static <T> Optional<T> of(T value)
From source file:io.kamax.mxisd.dns.FederationDnsOverwrite.java
public Optional<String> findHost(String lookup) { Entry mapping = mappings.get(lookup); if (mapping == null) { return Optional.empty(); }//from www . j a v a 2 s . c o m return Optional.of(mapping.getValue()); }
From source file:com.github.horrorho.inflatabledonkey.cloud.clients.MBKSyncClient.java
public static Optional<ProtectionZone> mbksync(HttpClient httpClient, CloudKitty kitty, Collection<Key<ECPrivate>> keys) throws IOException { List<CloudKit.ZoneRetrieveResponse> responses = kitty.zoneRetrieveRequest(httpClient, "_defaultZone", "mbksync"); logger.debug("-- baseZones() - responses: {}", responses); if (responses.size() != 2) { logger.warn("-- baseZones() - bad response list size: {}", responses); return Optional.empty(); }// w w w . j ava 2 s . c o m ProtectionZone zone = ProtectionZone.createBaseZone(keys); List<CloudKit.ProtectionInfo> protectionInfoList = zone(responses, zone); for (CloudKit.ProtectionInfo protectionInfo : protectionInfoList) { zone = zone.newProtectionZone(protectionInfo).orElse(zone); } return Optional.of(zone); }
From source file:de.lgblaumeiser.ptm.store.filesystem.FileStore.java
@Override public Optional<T> retrieveById(Long id) { checkState(id != null);//w w w. ja v a 2 s . c om File searchedFile = getFileInformation(id); if (!filesystemAccess.dataAvailable(searchedFile)) { return Optional.empty(); } try { return Optional.of(extractFileContent(filesystemAccess.retrieveFromFile(searchedFile))); } catch (IOException e) { return Optional.empty(); } }
From source file:com.devicehive.dao.rdbms.NetworkDaoRdbmsImpl.java
@Override public List<NetworkVO> findByName(String name) { List<Network> result = createNamedQuery(Network.class, "Network.findByName", Optional.of(CacheConfig.get())) .setParameter("name", name).getResultList(); Stream<NetworkVO> objectStream = result.stream().map(Network::convertNetwork); return objectStream.collect(Collectors.toList()); }
From source file:org.openmhealth.shim.runkeeper.mapper.RunkeeperPhysicalActivityDataPointMapper.java
@Override protected Optional<DataPoint<PhysicalActivity>> asDataPoint(JsonNode itemNode) { PhysicalActivity measure = getMeasure(itemNode); DataPointHeader header = getDataPointHeader(itemNode, measure); return Optional.of(new DataPoint<>(header, measure)); }
From source file:org.openwms.core.ServiceLayerExceptionTranslator.java
/** * Override method to handle the transaction yourself and skip to the default exception handling . * * @param ex Exception to handle/*from w w w . j a v a 2 s. c o m*/ * @return An empty Optional to use the default exception handling or an Exception to skip default handling */ @Override protected Optional<Exception> doTranslateException(Exception ex) { if (ex instanceof ConstraintViolationException) { return Optional.of(ex); } if (ex instanceof ServiceLayerException) { return Optional.of(ex); } return Optional.of(new ServiceLayerException(ex.getMessage())); }
From source file:org.trustedanalytics.cloud.cc.api.CcSpace.java
@JsonIgnore public String getName() { Optional<CcSpace> space = Optional.of(this); return space.map(CcSpace::getEntity).map(CcSpaceEntity::getName).orElse(null); }
From source file:org.springsource.restbucks.payment.PaymentRepositoryIntegrationTest.java
@Test public void savesCreditCardPayment() { CreditCard creditCard = creditCards.save(createCreditCard()); Order order = orders.save(createOrder()); CreditCardPayment payment = payments.save(new CreditCardPayment(creditCard, order)); assertThat(payment.getId(), is(notNullValue())); assertThat(payments.findByOrder(order), is(Optional.of(payment))); }
From source file:org.springsource.restbucks.payment.PaymentServiceIntegrationTest.java
@Test public void marksOrderAsPaid() { Order order = orders.save(createOrder()); CreditCard creditCard = creditCards.save(createCreditCard()); CreditCardPayment payment = paymentService.pay(order, creditCard.getNumber()); assertThat(paymentService.getPaymentFor(order), is(Optional.of(payment))); assertThat(order.isPaid(), is(true)); }
From source file:com.create.security.RepositoryUserDetailsService.java
private User getUser(String username) { return Optional.of(username).map(userRepository::findByUsername).filter(Objects::nonNull) .orElseThrow(() -> new UsernameNotFoundException("User " + username + " does not exists")); }