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:com.talvish.tales.parts.naming.NameManager.java

/**
 * Returns the requested validator.//from w  ww .  ja  v  a  2 s.  c  o  m
 * @param theArea the area representing the validator to get
 * @return the requested validator or null if not found
 */
public static NameValidator getValidator(String theArea) {
    Conditions.checkParameter(!Strings.isNullOrEmpty(theArea), "theArea", "area was not given");
    return validators.get(theArea);
}

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

/**
 * Generates and returns a unique device id.
 *
 * @param context//from w  ww  .j a va 2s.co m
 * @return
 */
public static String getDeviceId(Context context) {
    final MessageDigest md;
    try {
        md = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException();
    }

    final String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);

    if (!Strings.isNullOrEmpty(androidId)) {
        md.update(androidId.getBytes());
    } else {
        final Random random = new Random();
        byte randBytes[] = new byte[16];
        random.nextBytes(randBytes);
        md.update(randBytes);
    }

    final byte[] digest = md.digest();
    final byte[] shortDigest = Arrays.copyOfRange(digest, 0, 8);

    final String id = HexDump.toHexString(shortDigest);
    return id;
}

From source file:de.compeople.commons.net.proxy.ManualProxySelectorProvider.java

/**
 * Append a manual proxy selector to the CompoundProxySelector
 * /*  w  w w .ja v a  2 s.  c o m*/
 * @param compoundProxySelector
 */
public static void appendTo(CompoundProxySelector compoundProxySelector) {
    String proxyList = System.getProperty(MANUAL_PROXY_SETTINGS_PROPERTY);
    if (!Strings.isNullOrEmpty(proxyList)) {
        List<Proxy> universalProxies = new ArrayList<Proxy>();
        Map<String, List<Proxy>> protocolSpecificProxies = new HashMap<String, List<Proxy>>();

        if (!proxyList.equalsIgnoreCase(DIRECT)) {
            // if not direct requested fill the list from the spec.
            ProxySelectorUtils.fillProxyLists(proxyList, universalProxies, protocolSpecificProxies);
        }

        ManualProxySelector manualProxySelector = new ManualProxySelector(universalProxies,
                protocolSpecificProxies);

        compoundProxySelector.addOrReplace(100, manualProxySelector);
    } else {
        log.debug("No manual proxy (-D{}=... )selector requested.", MANUAL_PROXY_SETTINGS_PROPERTY);
    }
}

From source file:org.erlide.util.erlang.TermParser.java

protected static OtpErlangObject doParse(final String s) throws TermParserException {
    if (Strings.isNullOrEmpty(s)) {
        return null;
    }//  ww w  .  j av  a2  s  .c  o  m
    return parse(scan(s));
}

From source file:com.microsoft.applicationinsights.internal.util.MapUtil.java

public static <Value> void copy(Map<String, Value> source, Map<String, Value> target) {
    for (Map.Entry<String, Value> entry : source.entrySet()) {
        String key = entry.getKey();
        if (Strings.isNullOrEmpty(key)) {
            continue;
        }//from w  w w .  j a  va2  s.  c o m

        if (!target.containsKey(key)) {
            target.put(key, entry.getValue());
        }
    }
}

From source file:com.google.devtools.kythe.extractors.shared.IndexInfoUtils.java

public static CompilationDescription readIndexInfoFromFile(String indexInfoFilename) throws IOException {
    checkArgument(!Strings.isNullOrEmpty(indexInfoFilename), "indexInfoFilename");

    InputStream indexInfoInputStream = new GZIPInputStream(new FileInputStream(indexInfoFilename));
    try {/*ww w .  j  av a 2s.  co  m*/
        return readIndexInfoFromStream(indexInfoInputStream);
    } finally {
        indexInfoInputStream.close();
    }
}

From source file:org.erlide.util.erlang.OtpParser.java

protected static OtpErlangObject doParse(final String s) throws OtpParserException {
    if (Strings.isNullOrEmpty(s)) {
        return null;
    }//from  ww w  .j a v  a 2s.c o m
    return OtpParser.parse(OtpParser.scan(s));
}

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

/**
 * ??String//from ww w. java2s. c  om
 *
 * @param request
 * @param parameter
 * @param defau
 * @return
 */
public static String getString(HttpServletRequest request, String parameter, String defau) {
    String defaultValue = request.getParameter(parameter);
    if (Strings.isNullOrEmpty(defaultValue))
        return defau;
    return defaultValue;
}

From source file:qa.qcri.nadeef.web.sql.SQLUtil.java

public static boolean isValidInteger(String s) {
    boolean isGood = true;
    if (!Strings.isNullOrEmpty(s)) {
        try {/*from   w  w w.j a  v a 2 s .c o  m*/
            int ignore = Integer.parseInt(s);
        } catch (Exception ex) {
            isGood = false;
        }
    }
    return isGood;
}

From source file:org.wisdom.framework.osgi.Clauses.java

/**
 * Standard OSGi header parser. This parser can handle the format:
 * <ul>/*from w  w  w .j  a v  a  2 s .co m*/
 * <li>clauses ::= clause ( ',' clause ) +</li>
 * <li>clause ::= name ( ';' name ) (';' key '=' value )</li>
 * </ul>
 * <p>
 * The return structure is a Map of Map: <code>Map {name => Map {attribute | directive} => value}</code>.
 *
 * @param header the header to parse
 * @return the clauses
 */
static public Clauses parse(String header) {
    if (Strings.isNullOrEmpty(header)) {
        return new Clauses();
    }

    Clauses result = new Clauses();
    QuotedTokenizer qt = new QuotedTokenizer(header, ";=,");
    char del;
    do {
        boolean hadAttribute = false;
        Map<String, String> clause = new LinkedHashMap<>();
        List<String> aliases = new ArrayList<String>();
        aliases.add(qt.nextToken());
        del = qt.getSeparator();
        while (del == ';') {
            String name = qt.nextToken();
            if ((del = qt.getSeparator()) != '=') {
                // Found an ; or , - it's valid if we didn't find an attribute.
                if (hadAttribute) {
                    throw new IllegalArgumentException("Header contains name field after "
                            + "attribute or directive: " + name + " from " + header);
                }
                aliases.add(name);
            } else {
                // Parse attribute or directive.
                String value = qt.nextToken();
                clause.put(name, value);
                del = qt.getSeparator();
                hadAttribute = true;
            }
        }
        for (String packageName : aliases) {
            if (result.containsKey(packageName)) {
                LOGGER.warn("Duplicate package name in header: " + packageName
                        + ". Multiple package names in one clause are supported.");
            } else {
                result.put(packageName, clause);
            }
        }
    } while (del == ',');
    return result;
}