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

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

Introduction

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

Prototype

public static boolean isNullOrEmpty(@Nullable String string) 

Source Link

Document

Returns true if the given string is null or is the empty string.

Usage

From source file:org.datacleaner.documentation.DocumentationUtils.java

/**
 * Formats a string (typically a component {@link Description}) into an
 * appropriate set of HTML paragraphs ('p' tag).
 * /*w  w w. j a  va  2  s  . c  o  m*/
 * @param str
 * @return
 */
public static String createHtmlParagraphs(String str) {
    if (Strings.isNullOrEmpty(str)) {
        return "";
    }
    str = "<p>" + str + "</p>";
    str = StringUtils.replaceAll(str, "\n\n", "\n");
    str = StringUtils.replaceAll(str, "\n", "</p><p>");
    return str;
}

From source file:com.google.cloud.tools.appengine.cloudsdk.internal.args.Args.java

/**
 * Produces the flag form of a string value.
 *
 * @return {@code [--name, value]} or {@code []} if value is null.
 *///from  w w w  .ja  v a2 s .  co  m
static List<String> string(String name, String value) {
    if (!Strings.isNullOrEmpty(value)) {
        return Arrays.asList("--" + name, value);
    }
    return Collections.emptyList();
}

From source file:net.ltgt.guice.neo4j.Neo4jIndexProviders.java

public static Provider<Index<Node>> indexForNodes(final String name) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(name));
    return new Provider<Index<Node>>() {

        @Inject/*from  ww  w.  ja  va  2 s.  c o m*/
        IndexManager indexManager;

        @Override
        public Index<Node> get() {
            return indexManager.forNodes(name);
        }
    };
}

From source file:org.apache.druid.common.guava.GuavaUtils.java

/**
 * To fix semantic difference of Longs.tryParse() from Long.parseLong (Longs.tryParse() returns null for '+' started value)
 *//*from ww w  . jav a 2s. co  m*/
@Nullable
public static Long tryParseLong(@Nullable String string) {
    return Strings.isNullOrEmpty(string) ? null
            : Longs.tryParse(string.charAt(0) == '+' ? string.substring(1) : string);
}

From source file:org.apache.hadoop.hive.ql.exec.DagUtils.java

public static String getQueryName(Configuration conf) {
    String name = HiveConf.getVar(conf, HiveConf.ConfVars.HIVEQUERYNAME);
    if (Strings.isNullOrEmpty(name)) {
        return conf.get(MRJobConfig.JOB_NAME);
    } else {/* w  ww.  jav a  2 s  .  c  o m*/
        return name + " (" + conf.get(DagUtils.MAPREDUCE_WORKFLOW_NODE_NAME) + ")";
    }
}

From source file:com.dssmp.watch.util.RequestUtil.java

/**
 * ?//from w  w  w . ja  va2s.co m
 *
 * @param request
 * @param paraName
 * @param def
 * @return
 */
public static int getInt(HttpServletRequest request, String paraName, int def) {
    int res = def;
    String value = request.getParameter(paraName);
    if (!Strings.isNullOrEmpty(value))
        res = Integer.valueOf(value);
    return res;
}

From source file:com.google.enterprise.connector.notes.GsaUtil.java

static Collection<String> getGsaGroups(Collection<?> notesGroups, String groupPrefix) {
    if (notesGroups == null || notesGroups.size() == 0) {
        return Collections.emptySet();
    }/* w ww  .  ja  v a2 s .  c  om*/
    LinkedHashSet<String> gsaGroups = new LinkedHashSet<String>(notesGroups.size());
    // Prefix group names with the configured prefix.
    // Allow no prefix.
    if (Strings.isNullOrEmpty(groupPrefix)) {
        groupPrefix = "";
    } else if (!groupPrefix.endsWith("/")) {
        groupPrefix += "/";
    }
    for (Object groupObj : notesGroups) {
        String group = groupObj.toString();
        try {
            gsaGroups.add(URLEncoder.encode(groupPrefix + group.toLowerCase(), "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new AssertionError(e);
        }
    }
    return gsaGroups;
}

From source file:com.palantir.atlasdb.rocksdb.RocksDbNativeLibraryLoader.java

public static void load(String tmpDir) {
    String envTmpDir = System.getenv(ENV_VAR);
    if (!Strings.isNullOrEmpty(envTmpDir) && !envTmpDir.equals(tmpDir)) {
        throw new IllegalArgumentException("The temp dir for " + "native rocksdb libraries has been set to "
                + tmpDir + " by your kvs prefs, and to " + envTmpDir + " by the " + ENV_VAR
                + " environment variable.");
    }//from w  ww .  ja v a2s .  c o m
    if (staticTmpDir.compareAndSet(null, tmpDir)) {
        try {
            NativeLibraryLoader.getInstance().loadLibrary(tmpDir);
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
    } else if (!staticTmpDir.get().equals(tmpDir)) {
        log.error("Cannot load native rocksdb libraries to {}, " + "native libraries were already loaded to {}",
                tmpDir, staticTmpDir.get());
    }
}

From source file:org.apache.kylin.metrics.lib.ActiveReservoirReporter.java

public static Pair<String, String> getTableNameSplits(String tableName) {
    if (Strings.isNullOrEmpty(tableName)) {
        return null;
    }/*from  ww w  .  j ava  2s  . c  o m*/

    String[] splits = tableName.split(Pattern.quote("."));
    int i = 0;
    String database = splits.length == 1 ? KYLIN_PREFIX : splits[i++];
    String tableNameOnly = splits[i];
    return new Pair(database, tableNameOnly);
}

From source file:com.streamsets.pipeline.lib.xml.xpath.XPathValidatorUtil.java

public static String getXPathValidationError(String expression) {
    if (Strings.isNullOrEmpty(expression)) {
        return Constants.ERROR_EMPTY_EXPRESSION;
    } else if (expression.charAt(0) != Constants.PATH_SEPARATOR_CHAR) {
        if (expression.indexOf(Constants.PATH_SEPARATOR_CHAR) < 0) {
            // "legacy" expression
            if (XMLChar.isValidName(expression)) {
                return null;
            } else {
                return Constants.ERROR_INVALID_ELEMENT_NAME_PREFIX + expression;
            }//from w  ww .j  a  v a 2s .  c o  m
        } else {
            // expression that does not start with separator but is otherwise an XPath - not allowed
            return Constants.ERROR_XPATH_MUST_START_WITH_SEP + Constants.PATH_SEPARATOR_CHAR;
        }
    }

    boolean firstEmptyStringSeen = false;
    for (String str : expression.split(Constants.PATH_SEPARATOR)) {
        if (Strings.isNullOrEmpty(str)) {
            if (firstEmptyStringSeen) {
                return Constants.ERROR_DESCENDENT_OR_SELF_NOT_SUPPORTED;
            }
            firstEmptyStringSeen = true;
            continue;
        }
        final int predicateStartInd = str.indexOf('[');
        String elementName = str;
        if (predicateStartInd > 0) {
            elementName = str.substring(0, predicateStartInd);
            final String predicate = str.substring(predicateStartInd);
            final Matcher matcher = VALID_PREDICATE_PATTERN.matcher(predicate);
            if (!matcher.matches()) {
                return Constants.ERROR_INVALID_PREDICATE_PREFIX + predicate;
            } else {
                final String attributeName = matcher.group(1);
                if (!Strings.isNullOrEmpty(attributeName) && !XMLChar.isValidName(attributeName)) {
                    return Constants.ERROR_INVALID_ATTRIBUTE_PREFIX + attributeName;
                }
            }
        }
        if (!Constants.WILDCARD.equals(elementName) && !XMLChar.isValidName(elementName)) {
            return Constants.ERROR_INVALID_ELEMENT_NAME_PREFIX + elementName;
        }
    }
    return null;
}