Example usage for java.util Optional ofNullable

List of usage examples for java.util Optional ofNullable

Introduction

In this page you can find the example usage for java.util Optional ofNullable.

Prototype

@SuppressWarnings("unchecked")
public static <T> Optional<T> ofNullable(T value) 

Source Link

Document

Returns an Optional describing the given value, if non- null , otherwise returns an empty Optional .

Usage

From source file:com.dickthedeployer.dick.web.service.BuildService.java

@Transactional
public void onTrigger(TriggerModel model) throws BuildAlreadyQueuedException, RepositoryParsingException {
    Optional<Project> projectOptional = projectDao.findByNamespaceNameAndName(model.getNamespace(),
            model.getName());/*from w ww . j a v a  2s  .  c o  m*/
    Project project = projectOptional.get();
    log.info("Found project {} for name {}", project.getId(), model.getName());
    String sha = model.getSha();
    if (StringUtils.isEmpty(sha)) {
        sha = repositoryService.getLastSha(project);
    }
    List<EnvironmentVariable> environment = getEnvironment(model);
    try {
        String lastMessage = repositoryService.getLastMessage(project, sha);
        buildProject(project, sha, Optional.ofNullable(lastMessage), environment);
    } catch (CommandExecutionException ex) {
        throw new RepositoryParsingException(ex);
    }
}

From source file:com.orange.cloud.servicebroker.filter.securitygroups.filter.DeleteSecurityGroup.java

private Mono<String> securityGroupId(String securityGroup) {
    return Optional.ofNullable(securityGroup)
            .map(securityGroupName -> getSecurityGroupId(securityGroupName).map(ResourceUtils::getId))
            .orElse(Mono.error(new IllegalStateException("No security group to delete")));
}

From source file:com.netflix.genie.agent.execution.ExecutionContextImpl.java

/**
 * {@inheritDoc}
 */
@Override
public Optional<JobSpecification> getJobSpecification() {
    return Optional.ofNullable(jobSpecRef.get());
}

From source file:org.openmhealth.schema.domain.omh.SchemaVersion.java

public Optional<String> getQualifier() {
    return Optional.ofNullable(qualifier);
}

From source file:moe.yuna.palinuridae.core.BaseDao.java

/**
 * ???Map,key??,value//from   www.  j a v  a2  s.co  m
 *
 * @param tableName     ??
 * @param primaryColumn ??
 * @param primaryValue  
 * @return
 * @throws DBUtilException
 */
public Optional<Map<String, Object>> findById(String tableName, String primaryColumn, Object primaryValue)
        throws DBUtilException {
    try {
        Map<String, Object> columnValuePair = new HashMap<>();
        columnValuePair.put(primaryColumn, primaryValue);
        String sql = getDialect().findById(tableName, primaryColumn, "*");
        return Optional.ofNullable(getJdbcTemplate().queryForMap(sql, primaryValue));
    } catch (DataAccessException ex) {
        if (ex instanceof EmptyResultDataAccessException) {
            return Optional.empty();
        }
        throw new DBUtilException(ex);
    }
}

From source file:com.teradata.benchto.driver.BenchmarkProperties.java

public Optional<Path> getOverridesPath() {
    return Optional.ofNullable(overridesPath).map(Paths::get);
}

From source file:me.rkfg.xmpp.bot.plugins.FaggotOfTheDayPlugin.java

@Override
public String processCommand(Message message, Matcher matcher) throws LogicException, ClientAuthException {
    startListening();/*w  ww. jav  a2 s.c o m*/

    if (faggot == null) {
        calculateFaggot();
    }

    final Occupant sender = getMUCManager().getMUCOccupant(message.getFrom());
    final String senderJid = XmppStringUtils.parseBareJid(sender.getJid());
    final String faggotJid = XmppStringUtils.parseBareJid(faggot.getJid());
    if (senderJid.equals(faggotJid)) {
        return INFO_FAGGOT_IS_YOU;
    }

    final String roomJid = XmppStringUtils.parseBareJid(message.getFrom());
    final Occupant occupant = Optional.ofNullable(getMUCManager().listMUCOccupantsByJID(roomJid).get(faggotJid))
            .orElse(faggot);

    return INFO_FAGGOT_IS + occupant.getNick() + ".";
}

From source file:ch.algotrader.service.algo.AbstractAlgoOrderExecService.java

protected final Optional<S> getAlgoOrderState(final String intId) {
    S algoOrderState = this.algoOrderStates.get(intId);
    return Optional.ofNullable(algoOrderState);
}

From source file:org.pentaho.authentication.mapper.impl.AuthenticationMappingManagerImpl.java

public void onMappingServiceAdded(AuthenticationMappingService service, Map config) {
    if (service == null) {
        return;/* w ww  . j  av a 2s . c  om*/
    }

    int ranking = Optional.ofNullable(config.get(RANKING_CONFIG)).map(String::valueOf).map(Integer::parseInt)
            .orElse(50);

    serviceMap.put(new TypePair(service), new RankedAuthService(ranking, service));
}

From source file:cn.edu.zjnu.acm.judge.contest.ContestController.java

@ResponseBody
@GetMapping(value = "standing", produces = APPLICATION_JSON_VALUE)
public UserStanding[] standing(@PathVariable("contestId") long contestId) {
    Map<String, UserStanding> hashMap = new HashMap<>(80);
    contestMapper.standing(contestId)/*from www.  jav  a  2 s .c om*/
            .forEach(standing -> hashMap.computeIfAbsent(standing.getUser(), UserStanding::new)
                    .add(standing.getProblem(), standing.getTime(), standing.getPenalty()));
    contestMapper.attenders(contestId).forEach(attender -> Optional.ofNullable(hashMap.get(attender.getId()))
            .ifPresent(us -> us.setNick(attender.getNick())));
    UserStanding[] standings = hashMap.values().stream().sorted(UserStanding.COMPARATOR)
            .toArray(UserStanding[]::new);
    setIndexes(standings, Comparator.nullsFirst(UserStanding.COMPARATOR), UserStanding::setIndex);
    return standings;
}