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

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

Introduction

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

Prototype

public static String nullToEmpty(@Nullable String string) 

Source Link

Document

Returns the given string if it is non-null; the empty string otherwise.

Usage

From source file:com.google.gerrit.server.account.GetName.java

@Override
public String apply(AccountResource rsrc) {
    return Strings.nullToEmpty(rsrc.getUser().getAccount().getFullName());
}

From source file:org.onosproject.incubator.protobuf.models.net.RegionProtoTranslator.java

/**
 * Translates gRPC RegionProto message to {@link org.onosproject.net.region.Region}.
 *
 * @param region gRPC message//ww  w.j av a  2 s  .  c o m
 * @return {@link org.onosproject.net.region.Region}
 */
public static Region translate(RegionProtoOuterClass.RegionProto region) {
    RegionId id = RegionId.regionId(region.getRegionId());
    Region.Type type = RegionEnumsProtoTranslator.translate(region.getType()).get();
    String name = Strings.nullToEmpty(region.getName());

    List<Set<NodeId>> masters = new ArrayList<>();

    region.getMastersList().forEach(s -> {
        Set<NodeId> nodeIdSet = new HashSet<NodeId>();
        s.getNodeIdList().forEach(n -> {
            nodeIdSet.add(new NodeId(n));
        });
        masters.add(nodeIdSet);
    });

    Annotations annots = AnnotationsTranslator.asAnnotations(region.getAnnotations());

    return new DefaultRegion(id, name, type, annots, masters);
}

From source file:org.azolla.model.XmlConfigures.java

public static <T> void marshal(T t, String filePath) {
    try {/*from  w w w.  j a  v  a  2 s  . co  m*/
        getJAXBContext(t.getClass()).createMarshaller().marshal(t, new File(Strings.nullToEmpty(filePath)));
    } catch (Exception e) {
        throw new AzollaException(AzollaCode.MODELHELPER_MARSHAL, e).set("t", t).set("filePath", filePath);
    }
}

From source file:org.apache.hadoop.hive.ql.DriverFactory.java

public static IDriver newDriver(QueryState queryState, String userName, QueryInfo queryInfo) {
    boolean enabled = queryState.getConf().getBoolVar(ConfVars.HIVE_QUERY_REEXECUTION_ENABLED);
    if (!enabled) {
        return new Driver(queryState, userName, queryInfo);
    }//w ww  .  j  a va2  s .  c o m

    String strategies = queryState.getConf().getVar(ConfVars.HIVE_QUERY_REEXECUTION_STRATEGIES);
    strategies = Strings.nullToEmpty(strategies).trim().toLowerCase();
    ArrayList<IReExecutionPlugin> plugins = new ArrayList<>();
    for (String string : strategies.split(",")) {
        if (string.trim().isEmpty()) {
            continue;
        }
        plugins.add(buildReExecPlugin(string));
    }

    return new ReExecDriver(queryState, userName, queryInfo, plugins);
}

From source file:com.google.gerrit.server.account.GetStatus.java

@Override
public String apply(AccountResource rsrc) {
    return Strings.nullToEmpty(rsrc.getUser().getAccount().getStatus());
}

From source file:org.kegbot.app.util.Version.java

public static Version fromString(String versionStr) {
    final Matcher matcher = VERSION_RE.matcher(versionStr);
    if (!matcher.matches()) {
        return UNKNOWN;
    }/* w  ww.  j a v  a2 s . c om*/
    final int major = Integer.valueOf(matcher.group(1));
    final int minor = Integer.valueOf(matcher.group(2));
    final int micro = Integer.valueOf(matcher.group(3));
    final String extra = Strings.nullToEmpty(matcher.group(4));
    return new Version(major, minor, micro, extra);
}

From source file:com.google.gerrit.server.change.GetDescription.java

@Override
public String apply(RevisionResource rsrc) {
    return Strings.nullToEmpty(rsrc.getPatchSet().getDescription());
}

From source file:com.google.gerrit.server.change.GetTopic.java

@Override
public Object apply(ChangeResource rsrc) throws OrmException {
    return Strings.nullToEmpty(rsrc.getChange().getTopic());
}

From source file:org.lbogdanov.poker.core.AbstractEntity.java

/**
 * Ensures that an input string won't be longer than a specified limit, treats <code>null</code> as empty strings.
 * //from  w w  w  .  j a  v a  2 s. com
 * @param string the input string, can be <code>null</code>
 * @param maxLen the max length of the output string
 * @return the output string
 */
protected static String limitString(String string, int maxLen) {
    String str = Strings.nullToEmpty(string);
    return str.substring(0, Math.min(maxLen, str.length()));
}

From source file:org.trustedanalytics.servicebroker.hdfs.config.catalog.BrokerPlans.java

public static boolean isMultitenant(String planId) {
    return Strings.nullToEmpty(planId).toLowerCase().contains(TEMPLATE_KEY);
}