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:org.obm.push.mail.mime.MimeAddress.java

public static MimeAddress concat(MimeAddress firstPart, Integer secondPart) {
    String firstPartAddress = null;
    if (firstPart != null) {
        firstPartAddress = firstPart.getAddress();
    }//  w  w  w  .j a v  a  2s  . c o  m
    String secondPartAsString = null;
    if (secondPart != null) {
        secondPartAsString = String.valueOf(secondPart);
    }
    return new MimeAddress(
            Joiner.on(".").skipNulls().join(Strings.emptyToNull(firstPartAddress), secondPartAsString));
}

From source file:eu.thebluemountain.customers.dctm.brownbag.badcontentslister.ExtensionResolver.java

/**
 * The method that returns the extension to use for the format in the store
 * @param store carries a storage identifier
 * @param format carries a format's name
 * @return the extension if any/*from w w w.  ja v  a2  s.c  om*/
 */
public Optional<String> resolve(String store, String format) {
    if (this.stores.contains(store)) {
        return Optional.fromNullable(Strings.emptyToNull(this.extensions.apply(format)));
    }
    return Optional.absent();
}

From source file:com.google.gerrit.server.git.NotifyConfig.java

public void setFilter(String filter) {
    if ("*".equals(filter)) {
        this.filter = null;
    } else {/*from   ww w.  j ava2  s .  c  o  m*/
        this.filter = Strings.emptyToNull(filter);
    }
}

From source file:fathom.rest.security.aop.RequireTokenInterceptor.java

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {

    RequireToken requireToken = ClassUtil.getAnnotation(invocation.getMethod(), RequireToken.class);
    String tokenName = requireToken.value();

    Context context = RouteDispatcher.getRouteContext();
    // extract the named token from a header or a query parameter
    String token = Strings.emptyToNull(context.getRequest().getHeader(tokenName));
    token = Optional.fromNullable(token).or(context.getParameter(tokenName).toString(""));

    if (Strings.isNullOrEmpty(token)) {
        throw new AuthorizationException("Missing '{}' token", tokenName);
    }//from  w  ww.  j av  a  2 s . c o  m

    Account account = getAccount();
    if (account.isGuest()) {
        // authenticate by token
        TokenCredentials credentials = new TokenCredentials(token);
        account = securityManager.get().authenticate(credentials);
        if (account == null) {
            throw new AuthorizationException("Invalid '{}' value '{}'", tokenName, token);
        }
        context.setLocal(AuthConstants.ACCOUNT_ATTRIBUTE, account);
        log.debug("'{}' account authenticated by token '{}'", account.getUsername(), token);
    } else {
        // validate token
        account.checkToken(token);
    }

    return invocation.proceed();
}

From source file:org.obm.sync.calendar.RecurrenceId.java

public RecurrenceId(String recurrenceId) {
    this.recurrenceId = Strings.emptyToNull(recurrenceId);
}

From source file:com.googlesource.gerrit.plugins.messageoftheday.MessageOfTheDayImpl.java

@Inject
public MessageOfTheDayImpl(PluginConfigFactory configFactory, @PluginName String myName,
        @PluginData File data) {//from w  w  w.j a va2  s . com
    this.data = data;
    Config cfg = configFactory.getGlobalPluginConfig(myName);
    id = cfg.getString("message", null, "id");
    String configuredStartsAt = Strings.emptyToNull(cfg.getString("message", null, "startsAt"));
    startsAt = MoreObjects.firstNonNull(configuredStartsAt, now());
    expiresAt = cfg.getString("message", null, "expiresAt");
    msg = message();
}

From source file:org.sosy_lab.cpachecker.util.predicates.mathsat5.Mathsat5NativeApi.java

/**
 * Solve environment and check for satisfiability.
 * Return true if sat, false if unsat./* www . j  av  a 2 s .c o m*/
 */
public static boolean msat_check_sat(long e) throws InterruptedException {
    int res = msat_solve(e);
    switch (res) {
    case MSAT_SAT:
        return true;
    case MSAT_UNSAT:
        return false;
    default:
        String msg = Strings.emptyToNull(msat_last_error_message(e));
        String code = (res == MSAT_UNKNOWN) ? "\"unknown\"" : res + "";
        throw new IllegalStateException("msat_solve returned " + code + (msg != null ? ": " + msg : ""));
    }
}

From source file:org.obiba.mica.core.upgrade.ContactsRefactorUpgrade.java

@Override
public void execute(Version version) {
    log.info("Executing contacts upgrade");
    studyRepository.findAll().forEach(study -> {
        study.getAllPersons().forEach(p -> p.setEmail(Strings.emptyToNull(p.getEmail())));
        StudyState studyState = individualStudyService.findStateById(study.getId());

        studyRepository.saveWithReferences(study);

        eventBus.post(new DraftStudyUpdatedEvent(study));
        study.getAllPersons().forEach(c -> eventBus.post(new PersonUpdatedEvent(c)));

        if (studyState.isPublished()) {
            eventBus.post(/*w  w  w.  j  a  v  a 2s.  co m*/
                    new StudyPublishedEvent(study, studyState.getPublishedBy(), PublishCascadingScope.ALL));
        }
    });

    networkRepository.findAll().forEach(network -> {
        network.getAllPersons().forEach(p -> p.setEmail(Strings.emptyToNull(p.getEmail())));

        networkService.save(network, "System upgrade.");

        if (network.isPublished()) {
            networkService.publish(network.getId(), true);
        }
    });
}

From source file:fathom.xmlrpc.XmlRpcMethodRegistrar.java

public void addMethodGroup(Class<?> methodGroupClass) {
    String methodGroup = methodGroupClass.getName();
    if (methodGroupClass.isAnnotationPresent(XmlRpc.class)) {
        XmlRpc xmlrpc = ClassUtil.getAnnotation(methodGroupClass, XmlRpc.class);
        methodGroup = Optional.fromNullable(Strings.emptyToNull(xmlrpc.value())).or(methodGroup);
    }/*from w  ww.  j  av a2s. c  om*/
    addMethodGroup(methodGroup, methodGroupClass);
}

From source file:org.haiku.haikudepotserver.dataobjects.PkgLocalization.java

@Override
protected void validateForSave(ValidationResult validationResult) {

    String titleTrimmed = Strings.emptyToNull(Strings.nullToEmpty(getTitle()).trim());
    String descriptionTrimmed = Strings.emptyToNull(Strings.nullToEmpty(getDescription()).trim());
    String summaryTrimmed = Strings.emptyToNull(Strings.nullToEmpty(getSummary()).trim());

    if (!Objects.equals(titleTrimmed, getTitle())) {
        setTitle(titleTrimmed);/*w  w  w  .ja va  2 s.  c om*/
    }

    if (!Objects.equals(descriptionTrimmed, getDescription())) {
        setDescription(descriptionTrimmed);
    }

    if (!Objects.equals(summaryTrimmed, getSummary())) {
        setSummary(summaryTrimmed);
    }

    super.validateForSave(validationResult);

}