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.palantir.atlasdb.cli.services.ServicesConfigModule.java

private static JsonNode getConfigNode(ObjectMapper configMapper, File configFile, String configRoot)
        throws IOException {
    JsonNode node = configMapper.readTree(configFile);
    if (Strings.isNullOrEmpty(configRoot)) {
        return node;
    } else {/*from   w ww.j  ava 2s .c  o m*/
        JsonNode rootNode = findRoot(node, configRoot);
        if (rootNode != null) {
            return rootNode;
        }
        throw new IllegalArgumentException("Could not find " + configRoot + " in yaml file " + configFile);
    }
}

From source file:jp.tomorrowkey.irkit4j.http.HttpParameter.java

public HttpParameter(String key, String value) {
    if (Strings.isNullOrEmpty(key))
        throw new IllegalArgumentException("key must not be null or empty");
    if (Strings.isNullOrEmpty(value))
        throw new IllegalArgumentException("value must not be null or empty");

    this.key = key;
    this.value = value;
}

From source file:com.eucalyptus.network.NetworkMode.java

/**
 * Network mode from the value if present, else the given default
 *//* w ww.  ja  v a2  s  .c o  m*/
@Nonnull
public static NetworkMode fromString(@Nullable final String value, @Nonnull final NetworkMode defaultMode) {
    Parameters.checkParam("defaultMode", defaultMode, notNullValue());
    //noinspection ConstantConditions
    return !Strings.isNullOrEmpty(value) ? fromString(value) : defaultMode;
}

From source file:org.trustedanalytics.cfbroker.store.hdfs.helper.DirHelper.java

public static String concat(String path1, String path2) {
    if (Strings.isNullOrEmpty(path2)) {
        return path1;
    }//from  w w  w . j  a  v a 2  s.co m
    if (Strings.isNullOrEmpty(path1)) {
        return path2;
    }
    return removeTrailingSlashes(path1) + "/" + removeLeadingSlashes(path2);
}

From source file:de.aikiit.spamprotector.converter.SpamProtector.java

/**
 * Converts an encoded value into a plain one.
 *
 * @param input encoded value as set in an enumeration instance of this class.
 * @return encoded value or input if no mapping is found.
 *///from www.  j a va  2s. co  m
public static String toPlain(String input) {
    if (!Strings.isNullOrEmpty(input)) {
        String toTransform = input;
        StringBuilder result = new StringBuilder();

        while (!Strings.isNullOrEmpty(toTransform)) {
            int lengthBeforeConversion = toTransform.length();

            for (String prefix : ENCODED.keySet()) {
                // cut out any found items
                if (toTransform.startsWith(prefix)) {
                    result.append(ENCODED.get(prefix).getPlain());
                    toTransform = toTransform.substring(prefix.length(), toTransform.length());
                }
            }

            // in case we did not replace any character trim one and restart
            if (toTransform.length() == lengthBeforeConversion) {
                result.append(toTransform.charAt(0));
                toTransform = toTransform.substring(1);
            }
        }

        return result.toString();

    }
    return input;
}

From source file:org.opendaylight.mdsal.binding.generator.impl.YangTextTemplate.java

static String formatToParagraph(final String text, final int nextLineIndent) {
    if (Strings.isNullOrEmpty(text)) {
        return "";
    }/*w  w w .  j a va2s  .  co  m*/

    final StringBuilder sb = new StringBuilder();
    final StringBuilder lineBuilder = new StringBuilder();
    boolean isFirstElementOnNewLineEmptyChar = false;
    final String lineIndent = Strings.repeat(" ", nextLineIndent);

    String formattedText = NEWLINE_OR_TAB.removeFrom(text);
    formattedText = formattedText.replaceAll(" +", " ");

    final StringTokenizer tokenizer = new StringTokenizer(formattedText, " ", true);

    while (tokenizer.hasMoreElements()) {
        final String nextElement = tokenizer.nextElement().toString();

        if (lineBuilder.length() + nextElement.length() > 80) {
            // Trim trailing whitespace
            for (int i = lineBuilder.length() - 1; i >= 0 && lineBuilder.charAt(i) != ' '; --i) {
                lineBuilder.setLength(i);
            }

            // Trim leading whitespace
            while (lineBuilder.charAt(0) == ' ') {
                lineBuilder.deleteCharAt(0);
            }

            sb.append(lineBuilder).append('\n');
            lineBuilder.setLength(0);

            if (nextLineIndent > 0) {
                sb.append(lineIndent);
            }

            if (" ".equals(nextElement)) {
                isFirstElementOnNewLineEmptyChar = true;
            }
        }
        if (isFirstElementOnNewLineEmptyChar) {
            isFirstElementOnNewLineEmptyChar = false;
        } else {
            lineBuilder.append(nextElement);
        }
    }

    return sb.append(lineBuilder).append('\n').toString();
}

From source file:org.n52.shetland.ogc.HasDefaultEncoding.java

default boolean isSetDefaultElementEncoding() {
    return !Strings.isNullOrEmpty(getDefaultElementEncoding());
}

From source file:th.co.geniustree.dental.angular.validator.EmailUniqueValidator.java

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
    if (Strings.isNullOrEmpty(value)) {
        return true;
    }//from  ww  w.j  av a  2 s.c  o m
    Employee findByEmailIgnoreCase = employeeRepo.findByEmailIgnoreCase(value);
    return findByEmailIgnoreCase == null;
}

From source file:com.enonic.cms.core.search.facet.FacetBuilderFactory.java

public Set<FacetBuilder> buildFacetBuilder(ContentIndexQuery query) {
    Set<FacetBuilder> facetBuilders = Sets.newHashSet();

    String xml = query.getFacets();

    if (Strings.isNullOrEmpty(xml)) {
        return facetBuilders;
    }//from   www.j a v  a  2s.  c  o  m

    final FacetsModel facetsModel = facetsModelFactory.buildFromXml(xml);

    return facetModelEsFacetBuilder.build(facetsModel);
}

From source file:com.cloudant.mazha.matcher.IsNotEmpty.java

@Override
protected boolean matchesSafely(String item) {
    return !Strings.isNullOrEmpty(item);
}