Example usage for java.util Optional orElse

List of usage examples for java.util Optional orElse

Introduction

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

Prototype

public T orElse(T other) 

Source Link

Document

If a value is present, returns the value, otherwise returns other .

Usage

From source file:org.opensingular.form.wicket.mapper.DecimalMapper.java

private Integer getDecimalMaximo(IModel<? extends SInstance> model) {
    Optional<Integer> decimalMaximo = Optional
            .ofNullable(model.getObject().getAttributeValue(SPackageBasic.ATR_FRACTIONAL_MAX_LENGTH));
    return (Integer) decimalMaximo.orElse(DEFAULT_DIGITS);
}

From source file:com.athina.queue.manager.quartz.QuartzConfiguration.java

private SchedulerFactoryBean buildSchedulerFactory(JobFactory jobFactory, Optional<DataSource> dataSource,
        Properties properties) {//from  ww w .  j a v  a2  s .  c om
    SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
    schedulerFactoryBean.setJobFactory(jobFactory);
    schedulerFactoryBean.setDataSource(dataSource.orElse(null));
    schedulerFactoryBean.setQuartzProperties(properties);
    return schedulerFactoryBean;
}

From source file:se.curity.examples.oauth.OAuthJwtFilter.java

public void init(FilterConfig filterConfig) throws ServletException {
    ImmutableMultimap<String, String> initParams = initParamsMapFrom(filterConfig);

    _oauthHost = getInitParamValue(InitParams.OAUTH_HOST, initParams);
    int oauthPort = getInitParamValue(InitParams.OAUTH_PORT, initParams, Integer::parseInt);

    String webKeysPath = getInitParamValue(InitParams.JSON_WEB_KEYS_PATH, initParams);

    String scope = getInitParamValue(InitParams.SCOPE, initParams);
    _scopes = scope.split("\\s+");

    Optional<Long> minKidReloadTime = getOptionalInitParamValue(InitParams.MIN_KID_RELOAD_TIME, initParams,
            Long::parseLong);/*  w  w  w  . ja v  a  2  s  . co  m*/
    _minKidReloadTimeInSeconds = minKidReloadTime.orElse(_minKidReloadTimeInSeconds);

    synchronized (this) {
        if (_jwtValidator == null) {
            try {
                URI webKeysURI = new URI("https", null, _oauthHost, oauthPort, webKeysPath, null, null);
                _jwtValidator = new JwtValidatorWithJwk(webKeysURI, _minKidReloadTimeInSeconds, _httpClient);
            } catch (URISyntaxException e) {
                throw new ServletException("Invalid parameters", e);
            }
            _logger.info("{} successfully initialized", OAuthFilter.class.getSimpleName());
        } else {
            _logger.warn("Attempted to set webkey URI more than once! Ignoring further attempts.");
        }
    }
}

From source file:org.fineract.module.stellar.horizonadapter.HorizonServerEffectsListener.java

StellarCursorPersistency markPlace(final String pagingToken) {
    synchronized (stellarCursorRepository) {
        final Optional<StellarCursorPersistency> entry = stellarCursorRepository.findByCursor(pagingToken);

        return entry
                .orElse(stellarCursorRepository.save(new StellarCursorPersistency(pagingToken, new Date())));
    }//from w  ww.  j av  a  2 s . c o m
}

From source file:ch.ralscha.extdirectspring.provider.RemoteProviderOptional.java

@OptionalNamedMethod
public Optional<String> namedMethod3(@CookieValue("aSimpleCookie") Optional<String> cookie, Optional<Long> i) {
    return Optional.of(i.orElse(100L) + ":" + cookie.orElse("defaultCookieValue"));
}

From source file:com.blackducksoftware.integration.hub.detect.detector.rubygems.GemlockParser.java

private NameVersion parseNameVersion(final String trimmedLine) {
    final String[] pieces = trimmedLine.split(VERSION_PREFIX_PATTERN);
    String name = pieces[0].trim();
    String version = "";

    if (pieces.length > 1) {
        final Optional<String> validVersion = parseValidVersion(pieces[1].trim());
        version = validVersion.orElse("");
    }/*from  ww w  .j av  a  2 s . c o  m*/

    if (name.endsWith("!")) {
        name = name.substring(0, name.length() - 1);
    }

    return new NameVersion(name, version);
}

From source file:org.seedstack.i18n.internal.infrastructure.service.TranslationServiceImpl.java

@Override
public Map<String, String> getTranslationsForLocale(String locale) {
    Map<String, String> translations = new HashMap<>();
    for (Key key : keyRepository.loadAll()) {
        Optional<String> translation = getTranslationWithFallback(locale, key);
        if (translation.isPresent() || !i18nConfig.isAllowMissingTranslations()) {
            translations.put(key.getId(), translation.orElse("[" + key.getId() + "]"));
        }/*w ww.  j a va  2s  .c o  m*/
    }
    return translations;
}

From source file:ch.ralscha.extdirectspring.provider.RemoteProviderOptional.java

@OptionalNamedMethod
public Optional<String> namedMethod4(@RequestHeader("aSimpleHeader") Optional<String> header,
        Optional<BigDecimal> bd) {
    return Optional.of(bd.orElse(new BigDecimal("3.141")) + ":" + header.orElse("defaultHeaderValue"));
}

From source file:org.dcache.util.histograms.HistogramMetadata.java

public void setMaxValue(Optional<Double> maxValue) {
    this.maxValue = maxValue.orElse(null);
}

From source file:org.dcache.util.histograms.HistogramMetadata.java

public void setMinValue(Optional<Double> minValue) {
    this.minValue = minValue.orElse(null);
}