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.github.jcustenborder.kafka.connect.cdc.Assertions.java

public static void assertField(final Field expected, final Field actual, String message) {
    String prefix = Strings.isNullOrEmpty(message) ? "" : message + ": ";
    assertNotNull(expected, prefix + "expected field should not be null.");
    assertNotNull(actual, prefix + "actual field should not be null.");
    assertSchema(expected.schema(), actual.schema(),
            "schema for field " + expected.name() + " does not match.");
}

From source file:dk.dma.ais.abnormal.util.AisDataHelper.java

/**
 * Trim AIS string to Java String by converting all '@'s to spaces, and then
 * trimming all leading and trailing spaces away.
 *
 * @param name//from  w w w  .  j av  a 2 s .  c  o  m
 * @return
 */
public static String trimAisString(String name) {
    if (!Strings.isNullOrEmpty(name)) {
        name = name.replace('@', ' ').trim();
    } else {
        name = "";
    }
    return name;
}

From source file:uk.co.bubblebearapps.samplebot.HexValidator.java

/**
 * Validate hex with regular expression/* w  ww.j  av a  2 s.  c o  m*/
 *
 * @param hex hex for validation
 * @return true valid hex, false invalid hex
 */
public static boolean validate(final String hex) {

    if (Strings.isNullOrEmpty(hex)) {
        return false;
    }

    Matcher matcher = pattern.matcher(hex);
    return matcher.matches();

}

From source file:org.opendaylight.netconf.sal.restconf.impl.QueryParametersParser.java

public static WriterParameters parseWriterParameters(final UriInfo info) {
    WriterParameters.WriterParametersBuilder wpBuilder = new WriterParameters.WriterParametersBuilder();
    if (info == null) {
        return wpBuilder.build();
    }//  ww w.java2s  . c o m

    String param = info.getQueryParameters(false).getFirst(UriParameters.DEPTH.toString());
    if (!Strings.isNullOrEmpty(param) && !"unbounded".equals(param)) {
        try {
            final int depth = Integer.valueOf(param);
            if (depth < 1) {
                throw new RestconfDocumentedException(new RestconfError(RestconfError.ErrorType.PROTOCOL,
                        RestconfError.ErrorTag.INVALID_VALUE, "Invalid depth parameter: " + depth, null,
                        "The depth parameter must be an integer > 1 or \"unbounded\""));
            }
            wpBuilder.setDepth(depth);
        } catch (final NumberFormatException e) {
            throw new RestconfDocumentedException(new RestconfError(RestconfError.ErrorType.PROTOCOL,
                    RestconfError.ErrorTag.INVALID_VALUE, "Invalid depth parameter: " + e.getMessage(), null,
                    "The depth parameter must be an integer > 1 or \"unbounded\""));
        }
    }
    param = info.getQueryParameters(false).getFirst(UriParameters.PRETTY_PRINT.toString());
    wpBuilder.setPrettyPrint("true".equals(param));
    return wpBuilder.build();
}

From source file:com.infinities.keystone4j.utils.TextUtils.java

public static String get(String target, String defaultVal) {
    if (Strings.isNullOrEmpty(target)) {
        return defaultVal;
    }//from w  w  w .  jav  a 2  s. c  o  m
    return target;
}

From source file:com.haulmont.cuba.gui.components.SizeUnit.java

public static SizeUnit getUnitFromSymbol(String symbol) {
    if (Strings.isNullOrEmpty(symbol)) {
        return SizeUnit.PIXELS; // Defaults to pixels
    }//ww  w . ja v  a2  s.com

    for (SizeUnit unit : SizeUnit.values()) {
        if (symbol.equals(unit.getSymbol())) {
            return unit;
        }
    }

    throw new IllegalArgumentException("Passed symbol cannot be recognized as known SizeUnit");
}

From source file:de.aikiit.jmockex.OccurrenceFinder.java

public static boolean containsExactlyTimes(int times, String source, String marker) {
    if (Strings.isNullOrEmpty(source) || Strings.isNullOrEmpty(marker)) {
        throw new IllegalArgumentException("No null arguments allowed");
    }//from w  w  w  .ja v  a2s . c  o m
    return times == ((source.length() - source.replace(marker, "").length()) / marker.length());
}

From source file:com.cloudant.sync.util.CouchUtils.java

public static boolean isValidDocumentId(String docId) {
    // http://wiki.apache.org/couch/HTTP_Document_API#Documents
    if (Strings.isNullOrEmpty(docId)) {
        return false;
    }//from  w  w w  .j  a  v a 2  s .c  o  m

    if (docId.charAt(0) == '_') {
        return (docId.startsWith("_design/") || docId.startsWith("_local/"));
    }

    return true;
}

From source file:org.dbunitng.util.PropertyUtil.java

/**
 * Java Beans?????//from   ww  w. j  a  v  a  2 s  .  com
 * 
 * <pre>
 * decapitalizePropertyName(&quot;FirstName&quot;) = &quot;firstName&quot;
 * decapitalizePropertyName(&quot;AName&quot;) = &quot;AName&quot;
 * </pre>
 * 
 * @param name
 * @return ??
 */
public static String decapitalizePropertyName(String name) {
    if (Strings.isNullOrEmpty(name)) {
        return name;
    }
    if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) && Character.isUpperCase(name.charAt(0))) {

        return name;
    }
    char chars[] = name.toCharArray();
    chars[0] = Character.toLowerCase(chars[0]);
    return new String(chars);
}

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

public static Optional<PkgScreenshot> tryGetByCode(ObjectContext context, String code) {
    Preconditions.checkArgument(null != context, "the context must be supplied");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(code), "the code must be supplied");
    return Optional.ofNullable(ObjectSelect.query(PkgScreenshot.class).where(CODE.eq(code)).selectOne(context));
}