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:qa.qcri.qnoise.util.CSVTools.java

/**
 * Loads CSV file into database.//from  ww  w. j  a  va  2s.  c om
 * @param file CSV file path.
 * @param dbConfig DB connection config.
 * @param tableName target import table name.
 * @param delimiter CSV delimiter.
 * @return the number of bytes loaded into the target database.
 */
public static int load(String file, DBConfig dbConfig, String tableName, char delimiter) throws Exception {
    Preconditions.checkNotNull(dbConfig);
    Preconditions.checkNotNull(file);

    Connection conn = null;
    Statement stat = null;
    BufferedReader reader = null;
    int result = 0;
    try {
        conn = DBTools.createConnection(dbConfig, true);
        stat = conn.createStatement();
        if (DBTools.existTable(dbConfig, tableName)) {
            stat.executeUpdate("DROP TABLE " + tableName);
        }

        // create table based on the header
        reader = new BufferedReader(new FileReader(file));
        String header = reader.readLine();
        if (!Strings.isNullOrEmpty(header)) {
            String[] columns = header.split(Character.toString(delimiter));
            StringBuilder schemaSql = new StringBuilder("CREATE TABLE " + tableName + " (");
            boolean isFirst = true;
            for (String column : columns) {
                if (!isFirst) {
                    schemaSql.append(",");
                }
                isFirst = false;
                schemaSql.append(column).append(" VARCHAR(10240) ");
            }
            schemaSql.append(")");
            stat.execute(schemaSql.toString());

            SQLDialect dialect = dbConfig.getDialect();
            SQLDialectBase dialectBase = SQLDialectBase.createDialectBaseInstance(dialect);
            if (dialectBase.supportBulkLoad()) {
                result = dialectBase.bulkLoad(dbConfig, tableName, file, delimiter);
            } else {
                throw new UnsupportedOperationException("Non-bulk loading is not yet implemented.");
            }
        }
    } finally {
        try {
            if (stat != null) {
                stat.close();
            }

            if (conn != null) {
                conn.close();
            }

            if (reader != null) {
                reader.close();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return result;
}

From source file:org.apache.isis.core.metamodel.facets.object.domainobject.objectspecid.ObjectSpecIdFacetForJdoPersistenceCapableAnnotation.java

public static ObjectSpecIdFacet create(final JdoPersistenceCapableFacet persistenceCapableFacet,
        final FacetHolder holder) {

    if (persistenceCapableFacet.isNoop()) {
        return null;
    }/*w w  w .  j  a v  a2s.com*/
    final String schema = persistenceCapableFacet.getSchema();
    if (Strings.isNullOrEmpty(schema)) {
        return null;
    }
    final String objectType = schema.toLowerCase(Locale.ROOT) + "." + persistenceCapableFacet.getTable();
    return new ObjectSpecIdFacetForJdoPersistenceCapableAnnotation(objectType, holder);
}

From source file:com.parallax.server.blocklyprop.jsp.GetCdnUrl.java

@Override
public void doTag() throws JspException, IOException {
    if (!Strings.isNullOrEmpty(url)) {
        // System.out.println("Geturl: " + url);

        PageContext pageContext = (PageContext) getJspContext();
        JspWriter out = pageContext.getOut();

        String cdnUrl = Properties.getConfiguration().getString("cdnfiles.baseurl");
        if (pageContext.getRequest().isSecure()) {
            cdnUrl = cdnUrl.replaceFirst("http://", "https://");
            cdnUrl = Properties.getConfiguration().getString("cdnfiles.baseurl.https", cdnUrl);
        }/*from ww w. j av  a2s . c  o  m*/

        out.write(cdnUrl + (url.startsWith("/") ? "" : "/") + url);
    } else {
        System.out.println("Url = null or empty");
    }
}

From source file:org.apache.isis.core.metamodel.facets.object.value.annotcfg.ValueFacetAnnotation.java

private static String semanticsProviderName(final Class<?> annotatedClass,
        final IsisConfiguration configuration) {
    final Value annotation = annotatedClass.getAnnotation(Value.class);
    final String semanticsProviderName = annotation.semanticsProviderName();
    if (!Strings.isNullOrEmpty(semanticsProviderName)) {
        return semanticsProviderName;
    }// w  w w .  j  a  va2 s  .  c  om
    return ValueSemanticsProviderUtil.semanticsProviderNameFromConfiguration(annotatedClass, configuration);
}

From source file:org.obiba.opal.web.magma.vcs.Dtos.java

public static Opal.VcsCommitInfoDto asDto(CommitInfo commitInfo) {
    Opal.VcsCommitInfoDto.Builder commitInfoDtoBuilder = Opal.VcsCommitInfoDto.newBuilder() //
            .setAuthor(commitInfo.getAuthorName()) //
            .setDate(commitInfo.getDateAsIso8601()) //
            .setCommitId(commitInfo.getCommitId()) //
            .setComment(commitInfo.getComment()) //
            .setIsHead(commitInfo.isHead()) //
            .setIsCurrent(commitInfo.isCurrent());

    List<String> diffEntries = commitInfo.getDiffEntries();
    if (diffEntries != null) {
        commitInfoDtoBuilder.addAllDiffEntries(diffEntries);
    }/*  ww  w . ja v  a  2 s.c o  m*/
    String blob = commitInfo.getBlob();
    if (!Strings.isNullOrEmpty(blob)) {
        commitInfoDtoBuilder.setBlob(blob);
    }
    return commitInfoDtoBuilder.build();
}

From source file:org.apache.isis.core.progmodel.facets.object.parseable.ParserUtil.java

static String parserNameFromConfiguration(final Class<?> type, final IsisConfiguration configuration) {
    final String key = PARSER_NAME_KEY_PREFIX + type.getCanonicalName() + PARSER_NAME_KEY_SUFFIX;
    final String parserName = configuration.getString(key);
    return !Strings.isNullOrEmpty(parserName) ? parserName : null;
}

From source file:org.apache.isis.viewer.wicket.ui.components.layout.bs3.Util.java

public static void appendCssClass(final MarkupContainer markupContainer, final BS3ElementAbstract element,
        final String existingCssClass) {
    final String cssClass = existingCssClass
            + (!Strings.isNullOrEmpty(element.getCssClass()) ? (" " + element.getCssClass()) : "");
    CssClassAppender.appendCssClassTo(markupContainer, cssClass);
}

From source file:org.apache.mailet.AttributeName.java

public static AttributeName of(String name) {
    Preconditions.checkNotNull(name, "`name` is compulsory");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(name), "`name` should not be empty");

    return new AttributeName(name);
}

From source file:org.gsafeproject.storage.StorageApp.java

private static boolean isValid(String[] args) {
    if (1 >= args.length || Strings.isNullOrEmpty(args[1])) {
        System.out.println("Usage java -jar storage.jar server /path/configuration.yml");
        return false;
    }//from   w  ww  .j  ava  2 s . c o m
    if (!new File(args[1]).exists()) {
        throw new IllegalArgumentException(String.format("File %s does not exist.", args[1]));
    }
    return true;
}

From source file:org.glowroot.agent.webdriver.tests.SauceLabs.java

public static boolean useSauceLabs() {
    return !Strings.isNullOrEmpty(browserName) || !Strings.isNullOrEmpty(deviceName);
}