Example usage for org.apache.commons.lang3 StringUtils startsWithIgnoreCase

List of usage examples for org.apache.commons.lang3 StringUtils startsWithIgnoreCase

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils startsWithIgnoreCase.

Prototype

public static boolean startsWithIgnoreCase(final CharSequence str, final CharSequence prefix) 

Source Link

Document

Case insensitive check if a CharSequence starts with a specified prefix.

null s are handled without exceptions.

Usage

From source file:com.orm.androrm.migration.MigrationHelper.java

public List<String> getRelationTableNames(String table) {
    List<String> result = new ArrayList<String>();
    String sql = "SELECT name FROM sqlite_master WHERE type='table' AND (name LIKE '" + table
            + "#_%' OR name LIKE '%#_" + table + "' ESCAPE '#')";

    Cursor c = getCursor(sql);/*from  ww w  .j a  va2  s .c om*/

    while (c.moveToNext()) {
        String name = c.getString(c.getColumnIndexOrThrow("name"));

        if (!name.equalsIgnoreCase(table) && (StringUtils.startsWithIgnoreCase(name, table)
                || StringUtils.endsWithIgnoreCase(name, table))) {

            result.add(name);
        }
    }

    close(c);
    return result;
}

From source file:com.github.helenusdriver.driver.impl.SimpleStatementImpl.java

/**
 * Checks if the query string represents a "batch" statement.
 *
 * @author paouelle/* w w w  .j av a2s .co m*/
 *
 * @return <code>true</code> if the query string represents a "batch";
 *         <code>false</code> otherwise
 */
public boolean isBatch() {
    // don't any better ways to do this
    return StringUtils.startsWithIgnoreCase(query, "begin batch");
}

From source file:com.quinsoft.zeidon.objectdefinition.ViewAttribute.java

@Override
public void setAttribute(PortableFileReader reader) {
    String attributeName = reader.getAttributeName();

    switch (attributeName.charAt(0)) {
    case 'A':
        if (reader.getAttributeName().equals("AUTO_SEQ")) {
            autoSeq = true;/* w  ww  . j  ava  2s.c o  m*/
            viewEntity.setAutoSeq(this);
        }
        break;

    case 'D':
        // DERIVEDC is the name of the Java class that declares the derived function.
        // Java only (e.g. not in the C OE).
        if (reader.getAttributeName().equals("DERIVEDC")) {
            derivedOperationClassName = reader.getAttributeValue().intern();
        } else if (reader.getAttributeName().equals("DERIVEDF")) {
            derivedOperationName = reader.getAttributeValue().intern();
        } else if (reader.getAttributeName().equals("DOMAIN")) {
            Application app = viewEntity.getViewOd().getApplication();
            domainName = reader.getAttributeValue().intern();
            domain = app.getDomain(domainName);
        } else if (reader.getAttributeName().equals("DEBUGCHG")) {
            // requires commons-lang-2.4.jar or later
            debugChange = StringUtils.startsWithIgnoreCase(reader.getAttributeValue(), "Y");
        }
        break;

    case 'E':
        if (reader.getAttributeName().equals("ERATT_TOK")) {
            erAttributeToken = Long.parseLong(reader.getAttributeValue());
        }
        break;

    case 'F':
        if (reader.getAttributeName().equals("FORKEY")) {
            foreignKey = reader.getAttributeValue().toUpperCase().startsWith("Y");
        }
        break;

    case 'G':
        if (reader.getAttributeName().equals("GENKEY")) {
            genKey = true;
            viewEntity.setGenKey(this);
            viewEntity.getViewOd().setHasGenKey(true);
        }
        break;

    case 'H':
        if (reader.getAttributeName().equals("HASHKEY")) {
            if (hashKeyParent == null)
                hashKeyParent = getViewEntity().getParent();

            hashKeyType = AttributeHashKeyType.valueOf(reader.getAttributeValue());
            if (hashKeyType != AttributeHashKeyType.NONE)
                viewEntity.addHashKeyAttribute(this);
        } else if (reader.getAttributeName().equals("HASHKEY_PARENT")) {
            String entityName = reader.getAttributeValue();
            for (hashKeyParent = getViewEntity()
                    .getParent(); hashKeyParent != null; hashKeyParent = hashKeyParent.getParent()) {
                if (hashKeyParent.getName().equals(entityName))
                    break;
            }

            if (hashKeyParent == null)
                throw new ZeidonException("Unknown hashkey parent %s", entityName);
        } else if (reader.getAttributeName().equals("HIDDEN")) {
            hidden = reader.getAttributeValue().toUpperCase().startsWith("Y");
        }
        break;

    case 'I':
        if (reader.getAttributeName().equals("INIT")) {
            initialValue = reader.getAttributeValue();
            viewEntity.setHasInitializedAttributes(true);
        }

    case 'K':
        if (reader.getAttributeName().equals("KEY")) {
            key = true;
            viewEntity.addKey(this);
        }
        break;

    case 'L':
        if (reader.getAttributeName().equals("LTH")) {
            length = Integer.parseInt(reader.getAttributeValue());
        }
        break;

    case 'N':
        if (reader.getAttributeName().equals("NAME")) {
            attributeNumber = viewEntity.getAttributeCount();
            name = reader.getAttributeValue().intern();
        }
        break;

    case 'P':
        if (reader.getAttributeName().equals("PERSIST")) {
            persistent = reader.getAttributeValue().startsWith("Y");
        }
        break;

    case 'R':
        if (reader.getAttributeName().equals("REQUIRED")) {
            required = reader.getAttributeValue().startsWith("Y");
        }
        break;

    case 'S':
        if (reader.getAttributeName().equals("SEQUENCING")) {
            int position = Integer.parseInt(reader.getAttributeValue());

            // Find the first parent that can have multiple children.  If a parent has
            // max cardinality of 1 then it can't be ordered.
            ViewEntity search = viewEntity;
            while (search.getMaxCardinality() == 1)
                search = search.getParent();

            search.addSequencingAttribute(this, position);
        } else if (reader.getAttributeName().equals("SEQ_AD")) {
            isSequencingAscending = reader.getAttributeValue().toUpperCase().startsWith("A");
        }
        break;

    case 'T':
        if (reader.getAttributeName().equals("TYPE")) {
            type = InternalType.mapCode(reader.getAttributeValue());
        }
        break;

    case 'U':
        if (reader.getAttributeName().equals("UPDATE")) {
            update = reader.getAttributeValue().toUpperCase().startsWith("Y");
        }
        break;

    case 'X':
        if (reader.getAttributeName().equals("XVAATT_TOK")) {
            token = Integer.parseInt(reader.getAttributeValue());
        }
        break;
    }
}

From source file:gobblin.data.management.conversion.hive.query.HiveValidationQueryGenerator.java

/***
 * Generates Hive SQL that can be used to validate the quality between two {@link Table}s or optionally
 * {@link Partition}. The query returned is a basic join query that returns the number of records matched
 * between the two {@link Table}s./*from  w  w w . ja va2  s .  co  m*/
 * The responsibility of actually comparing this value with the expected module should be implemented by
 * the user.
 *
 * @param sourceTable Source Hive {@link Table} name.
 * @param sourceDb Source Hive database name.
 * @param targetTable Target Hive {@link Table} name.
 * @param optionalPartition Optional {@link Partition} to limit the comparison.
 * @return Query to find number of rows common between two tables.
 */
public static String generateDataValidationQuery(String sourceTable, String sourceDb, Table targetTable,
        Optional<Partition> optionalPartition, boolean isNestedORC) {

    StringBuilder sb = new StringBuilder();

    // Query head
    sb.append("SELECT count(*) FROM `").append(sourceDb).append("`.`").append(sourceTable).append("` s JOIN `")
            .append(targetTable.getDbName()).append("`.`").append(targetTable.getTableName())
            .append("` t ON \n");

    // Columns equality
    boolean isFirst = true;
    List<FieldSchema> fieldList = targetTable.getSd().getCols();
    for (FieldSchema field : fieldList) {

        // Do not add maps in the join clause. Hive does not support map joins LIHADOOP-21956
        if (StringUtils.startsWithIgnoreCase(field.getType(), "map")) {
            continue;
        }

        if (StringUtils.containsIgnoreCase(field.getType(), ":map")) {
            continue;
        }

        if (isFirst) {
            isFirst = false;
        } else {
            sb.append(" AND \n");
        }

        if (isNestedORC) {
            sb.append("\ts.`").append(field.getName()).append("`<=>");
        } else {
            // The source column lineage information is available in field's comment. Remove the description prefix "from flatten_source"
            String colName = field.getComment().replaceAll("from flatten_source ", "").trim();
            sb.append("\ts.`").append(colName.replaceAll("\\.", "`.`")).append("`<=>");
        }
        sb.append("t.`").append(field.getName()).append("` ");
    }
    sb.append("\n");

    // Partition projection
    if (optionalPartition.isPresent()) {
        Partition partition = optionalPartition.get();
        String partitionsInfoString = partition.getName();
        List<String> pInfo = Splitter.on(",").omitEmptyStrings().trimResults()
                .splitToList(partitionsInfoString);
        for (int i = 0; i < pInfo.size(); i++) {
            List<String> partitionInfoParts = Splitter.on("=").omitEmptyStrings().trimResults()
                    .splitToList(pInfo.get(i));

            if (partitionInfoParts.size() != 2) {
                throw new IllegalArgumentException(String.format(
                        "Partition details should be of the format partitionName=partitionValue. Recieved: %s",
                        pInfo.get(i)));
            }
            if (i == 0) {
                // add where clause
                sb.append(" WHERE \n");
            } else {
                sb.append(" AND ");
            }
            // add project for source and destination partition
            sb.append(String.format("s.`%s`='%s' ", partitionInfoParts.get(0), partitionInfoParts.get(1)));
            sb.append(" AND ");
            sb.append(String.format("t.`%s`='%s' ", partitionInfoParts.get(0), partitionInfoParts.get(1)));
        }
    }

    return sb.toString();
}

From source file:com.quinsoft.zeidon.objectdefinition.AttributeDef.java

@Override
public void setAttribute(PortableFileReader reader) {
    String attributeName = reader.getAttributeName();

    switch (attributeName.charAt(0)) {
    case 'A':
        if (reader.getAttributeName().equals("AUTO_SEQ")) {
            autoSeq = true;//from w  w  w.  ja  va2s  . c o  m
            entityDef.setAutoSeq(this);
        }
        break;

    case 'C':
        if (reader.getAttributeName().equals("CASESENS")) {
            isCaseSensitive = StringUtils.startsWithIgnoreCase(reader.getAttributeValue(), "Y");
        }
        break;

    case 'D':
        // DERIVEDC is the name of the Java class that declares the derived function.
        // Java only (e.g. not in the C OE).
        if (reader.getAttributeName().equals("DERIVEDC")) {
            derivedOperationClassName = reader.getAttributeValue().intern();
            if (!derivedOperationClassName.contains("."))
                derivedOperationClassName = getApplication().getPackage() + "." + derivedOperationClassName;
        } else if (reader.getAttributeName().equals("DERIVEDF")) {
            derivedOperationName = reader.getAttributeValue().intern();
        } else if (reader.getAttributeName().equals("DRSRCTYPE")) {
            derivedOperationsourceFileType = SourceFileType.parse(reader.getAttributeValue());
        } else if (reader.getAttributeName().equals("DOMAIN")) {
            setDomain(reader.getAttributeValue().intern());
        } else if (reader.getAttributeName().equals("DEBUGCHG")) {
            debugChange = StringUtils.startsWithIgnoreCase(reader.getAttributeValue(), "Y");
        }
        break;

    case 'E':
        if (reader.getAttributeName().equals("ERATT_TOK")) {
            erAttributeToken = reader.getAttributeValue().intern();
        }
        break;

    case 'F':
        if (reader.getAttributeName().equals("FORKEY")) {
            foreignKey = reader.getAttributeValue().toUpperCase().startsWith("Y");
        }
        break;

    case 'G':
        if (reader.getAttributeName().equals("GENKEY")) {
            genKey = true;
            entityDef.setGenKey(this);
            entityDef.getLodDef().setHasGenKey(true);
        }
        break;

    case 'H':
        if (reader.getAttributeName().equals("HASHKEY")) {
            if (hashKeyParent == null)
                hashKeyParent = getEntityDef().getParent();

            hashKeyType = AttributeHashKeyType.valueOf(reader.getAttributeValue());
            if (hashKeyType != AttributeHashKeyType.NONE)
                entityDef.addHashKeyAttribute(this);
        } else if (reader.getAttributeName().equals("HASHKEY_PARENT")) {
            String entityName = reader.getAttributeValue();
            for (hashKeyParent = getEntityDef()
                    .getParent(); hashKeyParent != null; hashKeyParent = hashKeyParent.getParent()) {
                if (hashKeyParent.getName().equals(entityName))
                    break;
            }

            if (hashKeyParent == null)
                throw new ZeidonException("Unknown hashkey parent %s", entityName);
        } else if (reader.getAttributeName().equals("HIDDEN")) {
            hidden = reader.getAttributeValue().toUpperCase().startsWith("Y");
        }
        break;

    case 'I':
        if (reader.getAttributeName().equals("INIT")) {
            initialValue = reader.getAttributeValue();
            entityDef.setHasInitializedAttributes(true);
        }

    case 'K':
        if (reader.getAttributeName().equals("KEY")) {
            key = true;
            entityDef.addKey(this);
        }
        break;

    case 'L':
        if (reader.getAttributeName().equals("LTH")) {
            length = Integer.parseInt(reader.getAttributeValue());
        }
        break;

    case 'N':
        if (reader.getAttributeName().equals("NAME")) {
            setName(reader.getAttributeValue().intern());
        }
        break;

    case 'P':
        if (reader.getAttributeName().equals("PERSIST")) {
            persistent = reader.getAttributeValue().startsWith("Y");
        }
        break;

    case 'R':
        if (reader.getAttributeName().equals("REQUIRED")) {
            required = reader.getAttributeValue().startsWith("Y");
        }
        break;

    case 'S':
        if (reader.getAttributeName().equals("SEQUENCING")) {
            int position = Integer.parseInt(reader.getAttributeValue());

            // Find the first parent that can have multiple children.  If a parent has
            // max cardinality of 1 then it can't be ordered.
            EntityDef search = entityDef;
            while (search.getMaxCardinality() == 1)
                search = search.getParent();

            search.addSequencingAttribute(this, position);
        } else if (reader.getAttributeName().equals("SEQ_AD")) {
            isSequencingAscending = reader.getAttributeValue().toUpperCase().startsWith("A");
        }
        break;

    case 'T':
        if (reader.getAttributeName().equals("TYPE")) {
            type = InternalType.mapCode(reader.getAttributeValue());
        }
        break;

    case 'U':
        if (reader.getAttributeName().equals("UPDATE")) {
            update = reader.getAttributeValue().toUpperCase().startsWith("Y");
        }
        break;

    case 'X':
        if (reader.getAttributeName().equals("XVAATT_TOK")) {
            xvaAttrToken = Integer.parseInt(reader.getAttributeValue());
        }
        break;
    }
}

From source file:it.cnr.isti.hpc.wikipedia.parser.ArticleParser.java

/**
 * @param article/*from w  w w .java2  s  .c o  m*/
 */
private void setIsList(Article article) {
    for (String list : locale.getListIdentifiers()) {
        if (StringUtils.startsWithIgnoreCase(article.getTitle(), list)) {
            article.setType(Type.LIST);
        }
    }

}

From source file:com.thinkbiganalytics.schema.QueryRunner.java

/**
 * Tests that the specified query is a SHOW, SELECT, DESC, or DESCRIBE query.
 *
 * @param query the query to test//from  www.j a  v  a  2 s.  c  o  m
 * @return {@code true} if the query is valid, or {@code false} otherwise
 */
private boolean validateQuery(@Nonnull final String query) {
    final String testQuery = StringUtils.trimToEmpty(query);
    return Arrays.stream(new String[] { "show", "select", "desc", "describe" })
            .anyMatch(prefix -> StringUtils.startsWithIgnoreCase(testQuery, prefix));
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlForm.java

/**
 * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
 *
 * <p>Submits this form to the server. If <tt>submitElement</tt> is {@code null}, then
 * the submission is treated as if it was triggered by JavaScript, and the <tt>onsubmit</tt>
 * handler will not be executed.</p>
 *
 * <p><b>IMPORTANT:</b> Using this method directly is not the preferred way of submitting forms.
 * Most consumers should emulate the user's actions instead, probably by using something like
 * {@link HtmlElement#click()} or {@link HtmlElement#dblClick()}.</p>
 *
 * @param submitElement the element that caused the submit to occur
 * @return a new page that reflects the results of this submission
 *//*from ww  w.j a va  2  s .co m*/
Page submit(final SubmittableElement submitElement) {
    final HtmlPage htmlPage = (HtmlPage) getPage();
    final WebClient webClient = htmlPage.getWebClient();
    if (webClient.getOptions().isJavaScriptEnabled()) {
        if (submitElement != null) {
            isPreventDefault_ = false;
            final ScriptResult scriptResult = fireEvent(Event.TYPE_SUBMIT);
            if (isPreventDefault_) {
                // null means 'nothing executed'
                if (scriptResult == null) {
                    return htmlPage;
                }
                return scriptResult.getNewPage();
            }
        }

        final String action = getActionAttribute().trim();
        if (StringUtils.startsWithIgnoreCase(action, JavaScriptURLConnection.JAVASCRIPT_PREFIX)) {
            return htmlPage.executeJavaScriptIfPossible(action, "Form action", getStartLineNumber())
                    .getNewPage();
        }
    } else {
        if (StringUtils.startsWithIgnoreCase(getActionAttribute(), JavaScriptURLConnection.JAVASCRIPT_PREFIX)) {
            // The action is JavaScript but JavaScript isn't enabled.
            // Return the current page.
            return htmlPage;
        }
    }

    final WebRequest request = getWebRequest(submitElement);
    final String target = htmlPage.getResolvedTarget(getTargetAttribute());

    final WebWindow webWindow = htmlPage.getEnclosingWindow();
    /** Calling form.submit() twice forces double download. */
    final boolean checkHash = !webClient.getBrowserVersion()
            .hasFeature(FORM_SUBMISSION_DOWNLOWDS_ALSO_IF_ONLY_HASH_CHANGED);
    webClient.download(webWindow, target, request, checkHash, false, "JS form.submit()");
    return htmlPage;
}

From source file:com.norconex.collector.http.robot.impl.StandardRobotsTxtProvider.java

private RobotData.Precision matchesUserAgent(String userAgent, String value) {
    if ("*".equals(value)) {
        return RobotData.Precision.WILD;
    }//from  ww  w  . j  ava2 s. co m
    if (StringUtils.equalsIgnoreCase(userAgent, value)) {
        return RobotData.Precision.EXACT;
    }
    if (value.endsWith("*")) {
        String val = StringUtils.removeEnd(value, "*");
        if (StringUtils.startsWithIgnoreCase(userAgent, val)) {
            return RobotData.Precision.PARTIAL;
        }
    }
    if (StringUtils.containsIgnoreCase(userAgent, value)) {
        return RobotData.Precision.PARTIAL;
    }
    return RobotData.Precision.NOMATCH;
}

From source file:it.cnr.isti.hpc.wikipedia.parser.ArticleParser.java

private void setRedirect(Article article) {
    if (!article.getRedirect().isEmpty())
        return;//from  www .  j  av a2  s .co m
    List<List<String>> lists = article.getLists();
    if ((!lists.isEmpty()) && (!lists.get(0).isEmpty())) {
        // checking only first item in first list
        String line = lists.get(0).get(0);

        for (String redirect : redirects) {
            if (StringUtils.startsWithIgnoreCase(line, redirect)) {
                int pos = line.indexOf(' ');
                if (pos < 0)
                    return;
                String red = line.substring(pos).trim();
                red = Article.getTitleInWikistyle(red);
                article.setRedirect(red);
                article.setType(Type.REDIRECT);
                return;

            }
        }
    }
}