Example usage for com.google.common.base Strings emptyToNull

List of usage examples for com.google.common.base Strings emptyToNull

Introduction

In this page you can find the example usage for com.google.common.base Strings emptyToNull.

Prototype

@Nullable
public static String emptyToNull(@Nullable String string) 

Source Link

Document

Returns the given string if it is nonempty; null otherwise.

Usage

From source file:com.google.template.soy.pysrc.restricted.PyFunctionExprBuilder.java

/**
 *  Returns a valid Python function call as a String.
 *//*from   w  w  w.jav  a 2  s.  c o  m*/
public String build() {
    StringBuilder sb = new StringBuilder(funcName + "(");

    Joiner joiner = Joiner.on(", ").skipNulls();

    // Join args and kwargs into simple strings.
    String args = joiner.join(Iterables.transform(argList, LIST_ARG_MAPPER));
    String kwargs = joiner.join(Iterables.transform(kwargMap.entrySet(), KEYWORD_ARG_MAPPER));

    // Strip empty strings.
    args = Strings.emptyToNull(args);
    kwargs = Strings.emptyToNull(kwargs);

    // Join all pieces together.
    joiner.appendTo(sb, args, kwargs, unpackedKwargs);

    sb.append(")");
    return sb.toString();
}

From source file:io.druid.query.filter.InDimFilter.java

private InDimFilter optimizeLookup() {
    if (extractionFn instanceof LookupExtractionFn && ((LookupExtractionFn) extractionFn).isOptimize()) {
        LookupExtractionFn exFn = (LookupExtractionFn) extractionFn;
        LookupExtractor lookup = exFn.getLookup();

        final List<String> keys = new ArrayList<>();
        for (String value : values) {

            // We cannot do an unapply()-based optimization if the selector value
            // and the replaceMissingValuesWith value are the same, since we have to match on
            // all values that are not present in the lookup.
            final String convertedValue = Strings.emptyToNull(value);
            if (!exFn.isRetainMissingValue()
                    && Objects.equals(convertedValue, exFn.getReplaceMissingValueWith())) {
                return this;
            }//w ww  .  ja  v  a  2 s  .c  o  m
            keys.addAll(lookup.unapply(convertedValue));

            // If retainMissingValues is true and the selector value is not in the lookup map,
            // there may be row values that match the selector value but are not included
            // in the lookup map. Match on the selector value as well.
            // If the selector value is overwritten in the lookup map, don't add selector value to keys.
            if (exFn.isRetainMissingValue() && lookup.apply(convertedValue) == null) {
                keys.add(convertedValue);
            }
        }

        if (keys.isEmpty()) {
            return this;
        } else {
            return new InDimFilter(dimension, keys, null);
        }
    }
    return this;
}

From source file:org.killbill.billing.plugin.analytics.AnalyticsListener.java

public AnalyticsListener(final OSGIKillbillLogService logService, final OSGIKillbillAPI osgiKillbillAPI,
        final OSGIKillbillDataSource osgiKillbillDataSource,
        final OSGIConfigPropertiesService osgiConfigPropertiesService, final Executor executor,
        final Clock clock, final DefaultNotificationQueueService notificationQueueService)
        throws NotificationQueueAlreadyExists {
    this.logService = logService;
    this.osgiKillbillAPI = osgiKillbillAPI;
    this.osgiConfigPropertiesService = osgiConfigPropertiesService;
    this.clock = clock;

    final String refreshDelayMaybeNull = Strings
            .emptyToNull(osgiConfigPropertiesService.getString(ANALYTICS_REFRESH_DELAY_PROPERTY));
    this.refreshDelaySeconds = refreshDelayMaybeNull == null ? 10 : Integer.valueOf(refreshDelayMaybeNull);

    final BusinessAccountDao bacDao = new BusinessAccountDao(logService, osgiKillbillDataSource);
    this.bstDao = new BusinessSubscriptionTransitionDao(logService, osgiKillbillDataSource, bacDao, executor);
    this.binAndBipDao = new BusinessInvoiceAndPaymentDao(logService, osgiKillbillDataSource, bacDao, executor);
    this.bosDao = new BusinessAccountTransitionDao(logService, osgiKillbillDataSource);
    this.bFieldDao = new BusinessFieldDao(logService, osgiKillbillDataSource);
    this.allBusinessObjectsDao = new AllBusinessObjectsDao(logService, osgiKillbillAPI, osgiKillbillDataSource,
            executor, clock);/*  w  ww .  java  2  s.co m*/
    this.currencyConversionDao = new CurrencyConversionDao(logService, osgiKillbillDataSource);

    final NotificationQueueHandler notificationQueueHandler = new NotificationQueueHandler() {

        @Override
        public void handleReadyNotification(final NotificationEvent eventJson, final DateTime eventDateTime,
                final UUID futureUserToken, final Long searchKey1, final Long searchKey2) {
            if (eventJson == null || !(eventJson instanceof AnalyticsJob)) {
                logService.log(LogService.LOG_ERROR,
                        "Analytics service received an unexpected event: " + eventJson);
                return;
            }

            final AnalyticsJob job = (AnalyticsJob) eventJson;

            // We need to check again if there is a duplicate because it's possible that 2 events were processed at the same time in handleKillbillEvent (e.g. ACCOUNT_CREATION and ACCOUNT_CHANGE)
            if (!shouldRun(job, futureUserToken, searchKey1, searchKey2)) {
                logService.log(LogService.LOG_DEBUG,
                        "Skipping already present notification for job " + job.toString());
                return;
            }

            try {
                handleAnalyticsJob(job);
            } catch (AnalyticsRefreshException e) {
                logService.log(LogService.LOG_ERROR, "Unable to process event", e);
            }
        }
    };
    jobQueue = notificationQueueService.createNotificationQueue(ANALYTICS_QUEUE_SERVICE, "refresh-queue",
            notificationQueueHandler);
    accountsBlacklist = BLACKLIST_SPLITTER.split(
            Strings.nullToEmpty(osgiConfigPropertiesService.getString(ANALYTICS_ACCOUNTS_BLACKLIST_PROPERTY)));
}

From source file:org.dcache.alarms.server.LogEntryServerWrapper.java

public void setEmailRecipients(String emailRecipients) {
    this.emailRecipients = Strings.emptyToNull(emailRecipients);
}

From source file:com.haulmont.cuba.web.gui.components.WebSourceCodeEditor.java

@SuppressWarnings("unchecked")
@Override// www.j  a  va  2  s  . com
public String getValue() {
    String value = super.getValue();
    return Strings.emptyToNull(value);
}

From source file:org.killbill.billing.plugin.analytics.dao.factory.BusinessFactoryBase.java

public BusinessFactoryBase(final CurrencyConversionDao currencyConversionDao,
        final OSGIKillbillLogService logService, final OSGIKillbillAPI osgiKillbillAPI,
        final OSGIConfigPropertiesService osgiConfigPropertiesService, final Clock clock) {
    this.logService = logService;
    this.osgiKillbillAPI = osgiKillbillAPI;
    this.clock = clock;
    this.referenceCurrency = Objects.firstNonNull(
            Strings.emptyToNull(osgiConfigPropertiesService.getString(ANALYTICS_REFERENCE_CURRENCY_PROPERTY)),
            "USD");
    this.currencyConversionDao = currencyConversionDao;
}

From source file:org.apache.awf.web.http.HttpResponseImpl.java

@Override
public void clearCookie(String name) {
    if (Strings.emptyToNull(name) != null) {
        setCookie(name, null, 0);
    }
}

From source file:org.dcache.alarms.server.LogEntryServerWrapper.java

public void setEmailSender(String emailSender) {
    this.emailSender = Strings.emptyToNull(emailSender);
}

From source file:de.bund.bfr.knime.pmm.js.common.Indep.java

/**
 * Sets the description of this {@link Indep}.
 * /*  ww w.j a  v  a  2  s.c om*/
 * Empty strings are converted to null.
 * 
 * @param description
 *            the description to be set
 */
public void setDescription(String description) {
    this.description = Strings.emptyToNull(description);
}

From source file:de.bund.bfr.knime.pmm.js.common.Misc.java

/**
 * Sets the original unit of this {@link Misc}.
 * //  w  ww .jav  a2s .  c o m
 * Empty strings are converted to null.
 * 
 * @param origUnit the original unit to be set
 */
public void setOrigUnit(final String origUnit) {
    this.origUnit = Strings.emptyToNull(origUnit);
}