List of usage examples for java.util Optional ofNullable
@SuppressWarnings("unchecked") public static <T> Optional<T> ofNullable(T value)
From source file:com.github.dmyersturnbull.transformations.ExtendedCommandLine.java
@Nonnull public Optional<String> get(char opt) { return Optional.ofNullable(m_commandLine.getOptionValue(opt)); }
From source file:org.lendingclub.mercator.aws.SQSScanner.java
@Override public Optional<String> computeArn(JsonNode n) { return Optional.ofNullable(n.path("aws_queueArn").asText(null)); }
From source file:org.ow2.proactive.connector.iaas.cloud.TagManager.java
@Autowired public TagManager(@Value("${connector-iaas-tag.key}") String connectorIaasTagKey, @Value("${connector-iaas-tag.value}") String connectorIaasTagValue) { connectorIaasTag = Tag.builder()/* ww w. j a v a 2s.co m*/ .key(Optional.ofNullable(connectorIaasTagKey).orElse(DEFAULT_CONNECTOR_IAAS_TAG_KEY)) .value(Optional.ofNullable(connectorIaasTagValue).orElse(DEFAULT_CONNECTOR_IAAS_TAG_VALUE)).build(); }
From source file:com.arpnetworking.configuration.jackson.BaseJacksonConfiguration.java
/** * {@inheritDoc}/*from w w w .j a va 2s . co m*/ */ @Override public Optional<String> getProperty(final String name) { final Optional<JsonNode> jsonNode = getJsonSource().getValue(name.split("\\.")); if (jsonNode.isPresent()) { return Optional.ofNullable(jsonNode.get().asText()); } return Optional.empty(); }
From source file:org.ow2.proactive.connector.iaas.service.InstanceService.java
public Set<Instance> createInstance(String infrastructureId, Instance instance) { Optional<Infrastructure> optionalInfrastructure = Optional .ofNullable(infrastructureService.getInfrastructure(infrastructureId)); Set<Instance> instancesCreated = optionalInfrastructure .map(infrastructure -> cloudManager.createInstance(infrastructure, instance)) .orElseThrow(() -> new NotFoundException( "infrastructure id : " + infrastructureId + " does not exists")); optionalInfrastructure.ifPresent(/*from www . jav a 2 s . c om*/ infrastructure -> instanceCache.registerInfrastructureInstances(infrastructure, instancesCreated)); return instancesCreated; }
From source file:org.openwms.common.location.LocationGroupServiceImpl.java
/** * {@inheritDoc}/*from w w w. ja v a 2 s . co m*/ */ @Override public Optional<LocationGroup> findByName(String name) { return Optional.ofNullable(locationGroupRepository.findByName(name)); }
From source file:com.atlassian.connect.spring.internal.AtlassianConnectContextModelAttributeProvider.java
private Optional<String> getHostBaseUrlFromPrincipal() { return Optional.ofNullable(SecurityContextHolder.getContext().getAuthentication()) .map(Authentication::getPrincipal).filter(AtlassianHostUser.class::isInstance) .map(AtlassianHostUser.class::cast).map(AtlassianHostUser::getHost).map(AtlassianHost::getBaseUrl); }
From source file:com.example.StateMachineConfiguration.java
@Override public void configure(final StateMachineConfigurationConfigurer<IssueStates, UserAction> config) throws Exception { config.withConfiguration().autoStartup(true) .listener(new StateMachineListenerAdapter<IssueStates, UserAction>() { @Override//from w w w . j a va2 s . com public void stateChanged(final State<IssueStates, UserAction> from, final State<IssueStates, UserAction> to) { final Optional<IssueStates> beforeState = Optional.ofNullable(from).map(State::getId); final Optional<IssueStates> afterState = Optional.ofNullable(to).map(State::getId); log.info("state change from: {}, to: {}", beforeState, afterState); } }); }
From source file:io.gravitee.repository.mongodb.management.MongoUserRepository.java
@Override public Optional<User> findByUsername(String username) throws TechnicalException { logger.debug("Find user by name user [{}]", username); UserMongo user = internalUserRepo.findOne(username); User res = mapper.map(user, User.class); logger.debug("Find user by name user [{}] - Done", username); return Optional.ofNullable(res); }