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:br.com.tecsinapse.exporter.converter.LongFromDecimalTableCellConverter.java

@Override
public Long apply(String input) {
    return Strings.isNullOrEmpty(input) ? null : new BigDecimal(input).longValue();
}

From source file:br.com.tecsinapse.exporter.converter.IntegerTableCellConverter.java

@Override
public Integer apply(String input) {
    return Strings.isNullOrEmpty(input) ? null : Integer.valueOf(input);
}

From source file:br.com.tecsinapse.exporter.converter.BigDecimalTableCellConverter.java

@Override
public BigDecimal apply(String input) {
    return Strings.isNullOrEmpty(input) ? null : new BigDecimal(input);
}

From source file:org.ow2.proactive.scheduling.api.graphql.beans.input.Inputs.java

public static final String buildQueryString(String after, String before, Integer first, Integer last,
        List<? extends ApiType> input) {

    if (!input.isEmpty() || !Strings.isNullOrEmpty(after) || !Strings.isNullOrEmpty(before) || first != null
            || last != null) {/*from ww w . ja  va 2 s .com*/
        StringBuilder sb = new StringBuilder();
        sb.append("(");
        if (!Strings.isNullOrEmpty(after)) {
            sb.append(' ').append(Arguments.AFTER.getName()).append(':').append(Constants.QUOTE).append(after)
                    .append(Constants.QUOTE);
        }
        if (!Strings.isNullOrEmpty(before)) {
            sb.append(' ').append(Arguments.BEFORE.getName()).append(':').append(Constants.QUOTE).append(before)
                    .append(Constants.QUOTE);
        }
        if (first != null) {
            sb.append(' ').append(Arguments.FIRST.getName()).append(':').append(first);
        }
        if (last != null) {
            sb.append(' ').append(Arguments.LAST.getName()).append(':').append(last);
        }
        if (!input.isEmpty()) {
            sb.append(' ').append(Arguments.FILTER.getName()).append(" : [");

            for (int i = 0; i < input.size(); i++) {
                ApiType apiType = input.get(i);

                sb.append(apiType.getQueryString());

                if (i < input.size() - 1) {
                    sb.append(',');
                }
            }

            sb.append("]");
        }
        sb.append(" )");
        return sb.toString();
    }
    return "";
}

From source file:com.talvish.tales.serialization.UrlEncoding.java

/**
 * URL encodes a string and hides the needed to handle an exception that should never happen.
 */// w w w .  ja v  a2  s.  c  o m
public static String encode(String theEncoding, String theString) {
    String encodedString = null;

    if (Strings.isNullOrEmpty(theEncoding)) {
        theEncoding = "UTF-8";
    }
    try {
        encodedString = URLEncoder.encode(theString, theEncoding);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(String.format("Didn't like '%s' encoding", theEncoding), e);
    }
    return encodedString;
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.MMXVersion.java

public static synchronized String getVersion() {
    if (version == null) {
        try {/*from  w  ww .  j  a  v  a  2s. c  o m*/
            InputStream inputStream = MMXVersion.class.getResourceAsStream("/" + VER_FILE_NAME);
            if (inputStream != null) {
                Properties props = new Properties();
                props.load(inputStream);
                String s = props.getProperty(VER_PROPERTY);
                if (!Strings.isNullOrEmpty(s)) {
                    version = s;
                }
            } else {
                LOGGER.trace("getVersion : file={} not found", VER_FILE_NAME);
            }
        } catch (Exception e) {
            LOGGER.error("getVersion : {}");
        }
    }
    return version == null ? "Version not available" : version;
}

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

public static Optional<PkgLocalization> getForPkgAndNaturalLanguageCode(ObjectContext context, Pkg pkg,
        final String naturalLanguageCode) {
    Preconditions.checkArgument(null != context, "the context must be supplied");
    Preconditions.checkArgument(null != pkg, "the pkg must be supplied");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(naturalLanguageCode),
            "the natural language code must be supplied");
    return findForPkg(context, pkg).stream()
            .filter(l -> l.getNaturalLanguage().getCode().equals(naturalLanguageCode))
            .collect(SingleCollector.optional());
}

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

/**
 * <p>Files can have extensions that help to signify what sort of files they are.  For example, a PNG file would
 * have the extension "png".  This method will be able to return a media type for a given file extension.</p>
 *//*w  w w.  j a  va 2 s .c  o m*/

public static Optional<MediaType> getByExtension(ObjectContext context, String extension) {
    Preconditions.checkArgument(null != context, "the context must be provided");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(extension), "the extension must be provided");

    if (extension.equals(EXTENSION_HAIKUVECTORICONFILE)) {
        return tryGetByCode(context, MEDIATYPE_HAIKUVECTORICONFILE);
    }

    if (extension.equals(EXTENSION_PNG)) {
        return tryGetByCode(context, com.google.common.net.MediaType.PNG.toString());
    }

    return Optional.empty();
}

From source file:br.com.tecsinapse.exporter.converter.IntegerFromBigDecimalTableCellConverter.java

@Override
public Integer apply(String input) {
    return Strings.isNullOrEmpty(input) ? null : new BigDecimal(input).intValue();
}

From source file:qa.qcri.nadeef.web.rest.WidgetAction.java

private static String getSubquery(String filter) {
    String sql = "VIOLATION";
    if (!Strings.isNullOrEmpty(filter)) {
        if (filter.startsWith(":=")) {
            String vid = filter.substring(2).trim();
            if (!Strings.isNullOrEmpty(vid)) {
                String[] tokens = vid.split(",");
                for (String token : tokens)
                    if (!SQLUtil.isValidInteger(token))
                        throw new IllegalArgumentException("Input is not valid.");
                sql = "(select * from VIOLATION where vid = any(array[" + vid + "])) a";
            }// w w  w . j  a  v  a2  s .c  om
        } else if (filter.startsWith("?=")) {
            String tid = filter.substring(2).trim();
            if (!Strings.isNullOrEmpty(tid)) {
                String[] tokens = tid.split(",");
                for (String token : tokens)
                    if (!SQLUtil.isValidInteger(token))
                        throw new IllegalArgumentException("Input is not valid.");
                sql = "(select * from VIOLATION where tid = any(array[" + tid + "])) a";
            }
        } else {
            sql = "(select * from VIOLATION where value like '%" + filter + "%') a";
        }
    }
    return sql;
}