Example usage for org.apache.commons.lang StringUtils countMatches

List of usage examples for org.apache.commons.lang StringUtils countMatches

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils countMatches.

Prototype

public static int countMatches(String str, String sub) 

Source Link

Document

Counts how many times the substring appears in the larger String.

Usage

From source file:ch.ksfx.web.services.seriesbrowser.SeriesBrowser.java

public void openNode(NavigationTreeNode ntn, StringBuilder markup, ComponentResources componentResources,
        List<String> nodes, List<String> filteredSeriesNames, List<String> openedNodes) {
    for (NavigationTreeNode child : ntn.getChildrens()) {
        openedNodes.add(child.getLocator());

        if (nodes.contains(child.getLocator())) {
            markup.append(snip/*from w  w  w  . ja v a2s.  co m*/
                    .replaceAll("#MARGIN#",
                            (new Integer(margin * StringUtils.countMatches(child.getLocator(), "-")))
                                    .toString())
                    .replaceAll("#NAME#",
                            Matcher.quoteReplacement("<a href='"
                                    + componentResources.createEventLink("closeNode", child.getLocator())
                                            .toURI()
                                    + "'><span class=\"glyphicon glyphicon-folder-open\"></span>&nbsp;&nbsp;"
                                    + child.getName() + "</a> "
                                    + getCategoryTitleMarkupForLocator(child.getLocator()))));
            for (TimeSeries ts : child.getSeries()) {
                if (filteredSeriesNames == null || filteredSeriesNames.isEmpty()
                        || filteredSeriesNames.contains(ts.getName())) {
                    markup.append(snip
                            .replaceAll("#MARGIN#",
                                    (new Integer(
                                            margin * (StringUtils.countMatches(child.getLocator(), "-") + 1)))
                                                    .toString())
                            .replaceAll("#NAME#",
                                    "<a href='"
                                            + pageRenderLinkSource.createPageRenderLinkWithContext(
                                                    "viewTimeSeries", ts.getId()).toURI()
                                            + "'><span class=\"glyphicon glyphicon-th-list\"></span>&nbsp;"
                                            + ts.getName() + "</a>"));
                }
            }

            openNode(child, markup, componentResources, nodes, filteredSeriesNames, openedNodes);
        } else {
            markup.append(snip
                    .replaceAll("#MARGIN#",
                            (new Integer(margin * StringUtils.countMatches(child.getLocator(), "-")))
                                    .toString())
                    .replaceAll("#NAME#",
                            Matcher.quoteReplacement("<a href='"
                                    + componentResources.createEventLink("openNode", child.getLocator()).toURI()
                                    + "'><span class=\"glyphicon glyphicon-folder-close\"></span>&nbsp;&nbsp;"
                                    + child.getName() + "</a> "
                                    + getCategoryTitleMarkupForLocator(child.getLocator()))));
        }
    }
}

From source file:com.google.gdt.eclipse.designer.model.widgets.panels.AbsolutePanelInfo.java

/**
 * @return {@link MethodInvocation}'s of this {@link JavaInfo}, where one of the arguments is
 *         given {@link WidgetInfo}.// w  w w  .  j  a  va2s .  c o  m
 * 
 * @param signature
 *          the signature of method, with <code>%widget%</code> at place where {@link WidgetInfo}
 *          argument is expected.
 */
private List<MethodInvocation> getInvocations(String signature, WidgetInfo widget) {
    // analyze/update signature
    int widgetIndex;
    {
        int widgetPatternIndex = signature.indexOf("%widget%");
        Assert.isTrue(widgetPatternIndex != -1, "No %%widget%% in %s.", signature);
        widgetIndex = StringUtils.countMatches(signature.substring(0, widgetPatternIndex), ",");
        signature = StringUtils.replace(signature, "%widget%", "com.google.gwt.user.client.ui.Widget");
    }
    // filter MethodInvocation's
    List<MethodInvocation> invocations = Lists.newArrayList();
    for (MethodInvocation invocation : getMethodInvocations(signature)) {
        Expression widgetExpression = DomGenerics.arguments(invocation).get(widgetIndex);
        if (widget.isRepresentedBy(widgetExpression)) {
            invocations.add(invocation);
        }
    }
    return invocations;
}

From source file:ch.elexis.data.Prescription.java

/**
 * Return the dose of a drugs as a list of up to 4 floats.<br>
 * Up to Version 3.0.10 (hopefully) Elexis did not specify exactly the dose of a drug, but used
 * a String where many doctors used shortcuts like 1-0-1-1 to specify that the number of
 * entities (e.g. a tablet) for breakfast, lunch, supper, before night Here are some examples
 * how this procedure deals with the some input. 0-0- 1/4-1/2 => <0.0,0.0,0.25> 0.5/-/- =>
 * <0.5> 0-0-0- 40E => <0.0,0.0,0.0,40.0> 0.5 Stk alle 3 Tage => <0.5> 1inj Wo => <>
 * // w w  w  .  j av  a  2 s  . c  o  m
 * More examples can be found in the unit test.
 * 
 * @return a list of (up to 4) floats
 */
public static ArrayList<Float> getDoseAsFloats(String dosis) {
    ArrayList<Float> list = new ArrayList<Float>();
    ArrayList<Float> sub_list = new ArrayList<Float>();
    float num = 0;
    if (dosis != null) {
        // Match stuff like '1/2', '7/8', '~1,2'
        // System.out.println(dosis.matches(special_num_at_start));
        if (dosis.matches(special_num_at_start)) {
            list.add(getNum(dosis.replace("~", "")));
        } else if (dosis.matches("[0-9]+([xX][0-9]+(/[0-9]+)?|)")) { //$NON-NLS-1$
            String[] dose = dosis.split("[xX]"); //$NON-NLS-1$
            float count = getNum(dose[0]);
            if (dose.length > 1)
                num = getNum(dose[1]) * count;
            else
                num = getNum(dose[0]);
            list.add(num);
        } else {
            sub_list = getDoseAsFloats(dosis, "-");
            if (StringUtils.countMatches(dosis, "-") > 1 && sub_list.size() > 0) {
                return sub_list;
            }
            sub_list = getDoseAsFloats(dosis, "/");
            if (StringUtils.countMatches(dosis, "/") > 1 && sub_list.size() > 0) {
                return sub_list;
            }
            if (dosis.indexOf('-') != -1 || dosis.indexOf('/') != -1) {
                String[] dos = dosis.split("[- /]"); //$NON-NLS-1$
                if (dos.length > 2) {
                    for (String d : dos) {
                        boolean hasDigit = d.matches("^[~/.]*[0-9].*");
                        if (d.indexOf(' ') != -1)
                            list.add(getNum(d.substring(0, d.indexOf(' '))));
                        else if (d.length() > 0 && hasDigit)
                            list.add(getNum(d));
                        if (list.size() >= 4)
                            return list;
                    }
                } else if (dos.length > 1) {
                    list.add(getNum(dos[1]));
                } else {
                    // nothing to add
                }
            }
        }
    }
    return list;
}

From source file:info.rmapproject.webapp.utils.WebappUtils.java

/**
 * Formats a snippet so that it is cut at a max number of characters, "<" and ">" are converted to html
 * and the "strong" tags aren't left open after this cut. 
 * NOTE: there is a known imperfections here that might result in some variation 
 * in string length e.g. a very long match with lots of highlighting may end up longer than 
 * other strings.//from  w  ww  .  j a v a 2s .c  o m
 * TODO: improve this based on note above, might be something that can be configured using solr?
 * @param text string to be formatted
 * @param max maximum length of display text (excludes html tags in length)
 * @return
 */
public static String formatSnippet(String text, int max) {
    if (text == null) {
        return null;
    }

    String snippet = text;

    int numHLs = StringUtils.countMatches(text, HL_PREFIX);
    int hlSpace = (HL_PREFIX.length() + HL_POSTFIX.length()) * numHLs;
    int actualMax = max + hlSpace;

    int firstPrefix = snippet.indexOf(HL_PREFIX);
    if (firstPrefix > actualMax) { //first match won't appear in snippet
        //so let's put the first match around the halfway point of the snippet
        snippet = snippet.substring(firstPrefix - Math.abs(actualMax / 2));
        //clean up partial word if there is one
        int firstSpace = snippet.indexOf(" ");
        firstPrefix = snippet.indexOf(HL_PREFIX);
        snippet = snippet.substring((firstSpace > 0 && firstSpace < firstPrefix) ? firstSpace + 1 : 0);
    }
    if (snippet.length() > actualMax) { //shorten
        int lastPostfixAfterMax = snippet.indexOf(HL_POSTFIX, (max + HL_PREFIX.length()));
        if (lastPostfixAfterMax > 0 && lastPostfixAfterMax < actualMax) {
            //close to cut point, we should end here instead
            snippet = snippet.substring(0, (lastPostfixAfterMax + HL_POSTFIX.length()));
        } else {
            //simple cut.
            snippet = snippet.substring(0, (max + hlSpace));
        }

        //make sure tags are closed
        if (StringUtils.countMatches(snippet, HL_PREFIX) > StringUtils.countMatches(snippet, HL_POSTFIX)) {
            snippet = snippet + HL_POSTFIX;
        }
    }

    snippet = snippet.replace("\\n", "");
    snippet = snippet.replace("<", "&lt;").replace(">", "&gt;");
    snippet = snippet.replace(HL_PREFIX, "<strong>").replace(HL_POSTFIX, "</strong>");

    return snippet;
}

From source file:com.impetus.client.mongodb.MongoDBClientFactory.java

/**
 * On set mongo server properties./*from   w ww .  jav a2  s .  co m*/
 * 
 * @param contactNode
 *            the contact node
 * @param defaultPort
 *            the default port
 * @param poolSize
 *            the pool size
 * @param addrs
 *            the addrs
 * @return the mongo client
 * @throws UnknownHostException
 *             the unknown host exception
 */
private MongoClient onSetMongoServerProperties(String contactNode, String defaultPort, String poolSize,
        List<ServerAddress> addrs) throws UnknownHostException {
    MongoClient mongo = null;
    MongoClientOptions mo = null;
    MongoDBSchemaMetadata metadata = MongoDBPropertyReader.msmd;
    ClientProperties cp = metadata != null ? metadata.getClientProperties() : null;
    Properties propsFromCp = null;
    if (cp != null) {
        DataStore dataStore = metadata != null ? metadata.getDataStore() : null;
        List<Server> servers = dataStore != null && dataStore.getConnection() != null
                ? dataStore.getConnection().getServers()
                : null;
        if (servers != null && !servers.isEmpty()) {
            for (Server server : servers) {
                addrs.add(
                        new ServerAddress(server.getHost().trim(), Integer.parseInt(server.getPort().trim())));
            }
        }

        propsFromCp = dataStore != null && dataStore.getConnection() != null
                ? dataStore.getConnection().getProperties()
                : null;
    } else {
        for (String node : contactNode.split(Constants.COMMA)) {
            if (StringUtils.countMatches(node, Constants.COLON) == 1) {
                // node is given with hostname and port
                // count == 1 is to exclude IPv6 addresses
                String host = node.split(":")[0];
                int port = Integer.parseInt(node.split(Constants.COLON)[1]);

                addrs.add(new ServerAddress(host.trim(), port));
            } else {
                addrs.add(new ServerAddress(node.trim(), Integer.parseInt(defaultPort.trim())));
            }
        }
    }

    MongoClientOptions.Builder b = new PopulateMongoOptions(propsFromCp, externalProperties).prepareBuilder();
    mo = b.build();

    if (mo.getConnectionsPerHost() <= 0 && !StringUtils.isEmpty(poolSize)) {
        mo = b.connectionsPerHost(Integer.parseInt(poolSize)).build();
    }

    mongo = new MongoClient(addrs, mo);

    return mongo;
}

From source file:com.aol.framework.helper.report.CustomizedReporter.java

synchronized private void generateTestExecutionStatus(boolean emailable, List<ISuite> suites,
        PrintWriter f_out) {//from   w w w  .j  av a  2 s.c  o m
    String testName = "";

    int totalPassedMethods = 0;
    int totalFailedMethods = 0;
    int totalSkippedMethods = 0;
    int totalSkippedConfigurationMethods = 0;
    int totalFailedConfigurationMethods = 0;
    int totalAutomationErrors = 0;
    int totalMethods = 0;

    int suite_totalPassedMethods = 0;
    int suite_totalFailedMethods = 0;
    int suite_totalSkippedMethods = 0;
    int suite_totalAutomationErrors = 0;

    String suite_passPercentage = "";
    String suiteName = "";

    ITestContext overview = null;
    HashMap<String, String> dashboardReportMap = new HashMap<String, String>();

    String dashboardAppGroup = "";

    for (ISuite suite : suites) {
        suiteName = suite.getName();
        TestHelper.logger.info(">> " + suiteName + " <<");
        Map<String, ISuiteResult> tests = suite.getResults();
        NumberFormat nf = NumberFormat.getInstance();

        for (ISuiteResult r : tests.values()) {
            overview = r.getTestContext();
            testName = overview.getName();

            totalPassedMethods = overview.getPassedTests().getAllMethods().size();
            totalFailedMethods = overview.getFailedTests().getAllMethods().size();
            totalAutomationErrors = overview.getFailedButWithinSuccessPercentageTests().getAllMethods().size();
            totalSkippedMethods = overview.getSkippedTests().getAllMethods().size();
            totalFailedConfigurationMethods = overview.getFailedConfigurations().getAllMethods().size(); // this should be 0 as redirected to automation error
            // totalMethods = overview.getAllTestMethods().length;
            totalMethods = totalPassedMethods + totalFailedMethods;

            nf.setMaximumFractionDigits(2);
            nf.setGroupingUsed(true);

            String includedModule = "";
            String includedGroup = "";

            ITestNGMethod[] allTestMethods = overview.getAllTestMethods();
            for (ITestNGMethod testngMethod : allTestMethods) {
                String[] modules = testngMethod.getGroups();
                for (String module : modules) {
                    for (String moduleName : TestHelper.MODULES) {
                        if (module.equalsIgnoreCase(moduleName)) {
                            if (!(includedModule.contains(module))) {
                                includedModule = includedModule + " " + module;
                            }
                        }
                    }
                    for (String groupName : TestHelper.TEST_GROUPS) {
                        if (module.equalsIgnoreCase(groupName)) {
                            if (!(includedGroup.contains(module))) {
                                includedGroup = includedGroup + " " + module;
                            }
                        }
                    }
                }
            }

            String[] nodeInfo = getNodeInfo(overview, testName);

            String browser = nodeInfo[1];
            String browser_version = nodeInfo[2];
            String platform = nodeInfo[0];
            //String nodeIp = nodeInfo[3];

            if (platform == null || platform.trim().length() == 0) {
                platform = "N/A";
            }

            if (browser_version == null || browser_version.trim().length() == 0) {
                browser_version = "N/A";
            }

            if (browser == null || browser.trim().length() == 0) {
                browser = "N/A";
            }

            if (!(dashboardReportMap.containsKey(includedModule))) {
                if (browser_version.equalsIgnoreCase("N/A")) {
                    browser_version = "";
                }
                dashboardReportMap.put(includedModule,
                        "os1~" + platform + "|browser1~" + browser + browser_version + "|testcase_count_1~"
                                + totalMethods + "|pass_count_1~" + totalPassedMethods + "|fail_count_1~"
                                + totalFailedMethods + "|skip_count_1~" + totalSkippedMethods
                                + "|skip_conf_count_1~" + totalSkippedConfigurationMethods
                                + "|fail_conf_count_1~" + totalFailedConfigurationMethods
                                + "|fail_automation_count_1~" + totalAutomationErrors);

            } else {
                for (String key : dashboardReportMap.keySet()) {

                    if (key.equalsIgnoreCase(includedModule)) {
                        if (browser_version.equalsIgnoreCase("N/A")) {
                            browser_version = "";
                        }
                        String value = dashboardReportMap.get(key);
                        int index = StringUtils.countMatches(value, "#") + 1;

                        index += 1;

                        value = value + "#" + "os" + index + "~" + platform + "|browser" + index + "~" + browser
                                + browser_version + "|testcase_count_" + index + "~" + totalMethods
                                + "|pass_count_" + index + "~" + totalPassedMethods + "|fail_count_" + index
                                + "~" + totalFailedMethods + "|skip_count_" + index + "~" + totalSkippedMethods
                                + "|skip_conf_count_" + index + "~" + totalSkippedConfigurationMethods
                                + "|fail_conf_count_" + index + "~" + totalFailedConfigurationMethods
                                + "|fail_automation_count_~" + totalAutomationErrors;
                        dashboardReportMap.put(key, value);
                    }
                }
            }

            dashboardAppGroup = includedGroup;
            suite_totalPassedMethods += totalPassedMethods;
            suite_totalFailedMethods += totalFailedMethods;
            suite_totalAutomationErrors += totalAutomationErrors;
            suite_totalSkippedMethods += totalSkippedMethods;

            suite_passPercentage = getPercentage(nf, suite_totalPassedMethods,
                    suite_totalPassedMethods + suite_totalFailedMethods);

        }

    }

    if (!doneOutputToConsole) {
        //**************************** report to console as status ******************

        int suite_totalTestedMethods = suite_totalPassedMethods + suite_totalFailedMethods;

        System.out.println("[TOTAL_METHODS]: " + (suite_totalTestedMethods));

        System.out.println("[PASSED_METHODS]: " + suite_totalPassedMethods);
        if (suite_totalFailedMethods > 0 || suite_totalPassedMethods == 0)
            System.out.println("[FAILED_METHODS]: " + suite_totalFailedMethods);
        if (suite_totalAutomationErrors > 0)
            System.out.println("[AUTOMATION_ERRORS]: " + suite_totalAutomationErrors);
        if (suite_totalSkippedMethods > 0)
            System.out.println("[SKIPPED_METHODS]: " + suite_totalSkippedMethods);

        System.out.println("[PASSED%]: " + suite_passPercentage);

        TestHelper.setReportProperties(suite_totalTestedMethods, suite_totalPassedMethods,
                suite_totalFailedMethods, suite_totalSkippedMethods, suite_passPercentage,
                suite_totalAutomationErrors);
        //********************************************************************************
    }

    StringBuilder dashboardResults = new StringBuilder();
    if (!emailable) {
        dashboardResults.append(
                "<table id=\"myTable\" width=\"100%\" cellspacing=0 cellpadding=0 class=\"tablesorter\">");
    } else {
        dashboardResults.append("<table " + classParam + " cellspacing=\"0\" cellpadding=\"0\" width=\"91%\">");
    }
    dashboardResults
            // .append("<thead><tr> <th>Test Name</th><th>"
            .append("<thead><tr> <th>Module Name</th><th>" + " # Unique TestCases</th><th>"
                    + " # Combinations</th><th>" + " # Passed</th><th>" + " # Failed</th><th>"
                    + " # Warning</th><th>" + " # Skipped</th><th>" + "# Total</th><th>"
                    + "Success Rate</th> </tr> </thead> <tbody>");

    int total_browser_combinations = 0;
    int total_unique_testcases = 0;

    for (String key : dashboardReportMap.keySet()) {

        String fileName = key.trim() + "-Overall" + "-customized-report.html";
        if (!emailable) {

            try {
                generateModuleOverallTestReport(testName, key, suites, fileName);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        String value = dashboardReportMap.get(key);
        String[] values = value.split("#");

        int testcase_count = 0; //*******************************************
        int pass_count = 0;
        int fail_count = 0;
        int fail_automation_count = 0;
        int skip_count = 0;
        int skip_conf_count = 0;
        int fail_conf_count = 0;
        String appKey = "TEST_APP";
        String appName = TestHelper.getTestConfig(appKey);

        if (dashboardAppGroup.contains("Smoke") && !appName.equalsIgnoreCase("webmail")) {
            appName = appName + "_" + "Smoke";

        } else if (dashboardAppGroup.contains("Regression")) {
            appName = appName + "_" + "Regression";
        }

        String dashboardModule = key;
        //
        //            if (dashboardModule.contains("Compose"))
        //            {
        //                dashboardModule = dashboardModule.replace("Compose", "ComposeMail");
        //            } else if (dashboardModule.contains("Read"))
        //            {
        //                dashboardModule = dashboardModule.replace("Read", "ReadMail");
        //            }

        // int countMatches = StringUtils.countMatches(value, "#") + 1;

        for (String val : values) {

            String[] tokens = val.split("\\|");
            for (String token : tokens) {
                if (token.contains("testcase_count")) {
                    testcase_count = testcase_count + Integer.parseInt(token.split("~")[1]);
                }
                if (token.contains("pass_count")) {
                    pass_count = pass_count + Integer.parseInt(token.split("~")[1]);
                }
                if (token.contains("fail_count")) {
                    fail_count = fail_count + Integer.parseInt(token.split("~")[1]);
                }
                if (token.contains("fail_automation_count")) {
                    fail_automation_count = fail_automation_count + Integer.parseInt(token.split("~")[1]);
                }
                if (token.contains("skip_count")) {
                    skip_count = skip_count + Integer.parseInt(token.split("~")[1]);
                }
                if (token.contains("skip_conf_count")) {
                    skip_conf_count = skip_conf_count + Integer.parseInt(token.split("~")[1]);
                }
                if (token.contains("fail_conf_count")) {
                    fail_conf_count = fail_conf_count + Integer.parseInt(token.split("~")[1]);
                }
            }

            testcase_count -= skip_count + skip_conf_count + fail_conf_count;
        }

        NumberFormat nformat = NumberFormat.getInstance();
        nformat.setMaximumFractionDigits(2);
        nformat.setGroupingUsed(true);
        String passPercent = getPercentage(nformat, pass_count, pass_count + fail_count);

        String finalStr = "[";
        String[] val = dashboardReportMap.get(key).split("#");

        int unique_testcase = 0;

        int limit = val.length - 1;
        for (int i = 0; i < val.length; i++) {//TODO - unique_testcase is the max num cases among tests, not the total for the module across tests - Steven
            String testCaseCount = (val[i].split("\\|")[2]).split("~")[1];
            int next = Integer.parseInt(testCaseCount);
            if (next > unique_testcase) {
                unique_testcase = next;
            }
            finalStr = finalStr + testCaseCount + " T * 1 B]";
            if (i != limit) {
                finalStr += " + [";
            }
        }
        //unique_testcase = 
        String finalString = "";
        //            if ((unique_testcase * values.length) != (pass_count + fail_count + skip_count))
        //            {
        //                finalString = "<a href=\"#\" title=\"" + finalStr + "\">" + (pass_count + fail_count + skip_count)
        //                        + "</a>";
        //                
        //            } else
        {
            finalString = String.valueOf((pass_count + fail_count + fail_automation_count + skip_count));
        }

        String passCount = "";
        String failCount = "";
        String automationErrorCount = "";
        String skipCount = "";

        if (pass_count > 0) {
            passCount = "<td bgcolor=\"" + passColor + "\"><font color=\"white\"><b>" + pass_count
                    + "</b></font></td>";
        } else {
            passCount = "<td>" + pass_count + "</td>";
        }

        if (fail_count > 0) {
            failCount = "<td bgcolor=\"" + failColor + "\"><font color=\"white\"><b>" + fail_count
                    + "</b></font></td>";
        } else {
            failCount = "<td>" + fail_count + "</td>";
        }
        if (fail_automation_count > 0) {
            automationErrorCount = "<td bgcolor=\"" + warnColor + "\"><font color=\"white\"><b>"
                    + fail_automation_count + "</b></font></td>";
        } else {
            automationErrorCount = "<td>" + fail_automation_count + "</td>";
        }

        if (skip_count > 0) {
            skipCount = "<td bgcolor=\"" + skipColor + "\"><font color=\"white\"><b>" + skip_count
                    + "</b></font></td>";
        } else {
            skipCount = "<td>" + skip_count + "</td>";
        }
        if (!emailable || !disableCss) {
            dashboardResults.append("<tr><td><b><a href='" + TestHelper.jenkinsBuildUrl
                    + TestHelper.jenkinsCustomReportTitle + TestHelper.customReportDirLink + fileName + "'>"
                    + dashboardModule + "</b></td><td>"
                    // + testName + "</b></td><td>"  
                    + unique_testcase + "</td><td>" + values.length + "</td>" + passCount + failCount
                    + automationErrorCount + skipCount + "<td>" + finalString + "</td><td><font color=\""
                    + passPercentageColor + "\"><b>" + passPercent + " %" + "</b></font></td></tr>");
        } else {
            dashboardResults.append("<tr><td><b>" + dashboardModule + "</b></td><td>"
            //+ testName + "</b></td><td>"  
                    + unique_testcase + "</td><td>" + values.length + "</td><td>" + pass_count + "</td><td>"
                    + fail_count + "</td><td>" + fail_automation_count + "</td><td>" + skip_count + "</td><td>"
                    + finalString + "</td><td><b>" + passPercent + " %" + "</td></tr>");
        }
        if (total_browser_combinations < values.length) {
            total_browser_combinations = values.length;
        }

        total_unique_testcases += unique_testcase;
    }

    dashboardResults.append("</tbody></table>");

    if (!emailable || !disableCss) {
        String suite_pass = "";
        String suite_fail = "";
        String suite_automation_error = "";
        String suite_skip = "";

        if (suite_totalPassedMethods > 0) {
            suite_pass = "<td bgcolor=\"" + passColor + "\"><font color=\"white\"><b>"
                    + suite_totalPassedMethods + "</b></font></td>";
        } else {
            suite_pass = "<td>" + suite_totalPassedMethods + "</td>";
        }

        if (suite_totalFailedMethods > 0) {
            suite_fail = "<td bgcolor=\"" + failColor + "\"><font color=\"white\"><b>"
                    + suite_totalFailedMethods + "</b></font></td>";
        } else {
            suite_fail = "<td>" + suite_totalFailedMethods + "</td>";
        }
        if (suite_totalAutomationErrors > 0) {
            suite_automation_error = "<td bgcolor=\"" + warnColor + "\"><font color=\"white\"><b>"
                    + suite_totalAutomationErrors + "</b></font></td>";
        } else {
            suite_automation_error = "<td>" + suite_totalAutomationErrors + "</td>";
        }
        if (suite_totalSkippedMethods > 0) {
            suite_skip = "<td bgcolor=\"" + skipColor + "\"><font color=\"white\"><b>"
                    + suite_totalSkippedMethods + "</b></font></td>";
        } else {
            suite_skip = "<td>" + suite_totalSkippedMethods + "</td>";
        }

        // Summary Table
        f_out.println("<p><b>Overall Execution Summary</b></p>");

        if (!emailable) {
            f_out.println("<table class=\"tablesorter\" width=\"100%\">");
        } else {
            f_out.println("<table " + classParam + "  cellspacing=\"0\" cellpadding=\"0\" width=\"91%\">");
        }
        f_out.println(//"<table class=\"param\" width=\"100%\">"+
                "<thead><tr><th>Test Suite Name</th><th>" + "# Unique TestCases</th><th>"
                        + "# Combinations</th> <th>" + "# Passed</th> <th>" + "# Failed</th> <th>"
                        + "# Warning</th> <th>" + "# Skipped</th><th>" + "# Total</th> <th>"
                        + "Success Rate</th> </tr> </thead>" + " <tbody> <tr><td><b>" + suiteName
                        + "</b></td><td>" + total_unique_testcases + "</td><td>" + total_browser_combinations
                        + "</td>" + suite_pass + suite_fail + suite_automation_error + suite_skip + "<td>"
                        + (suite_totalPassedMethods + suite_totalFailedMethods + suite_totalSkippedMethods
                                + suite_totalAutomationErrors)
                        + "</td><td><font color=\"" + passPercentageColor + "\"><b>" + suite_passPercentage
                        + " %" + "</b></font></td></tr></tbody></table>");
    } else {
        f_out.println("<b><font color=\"" + titleColor + "\">Overall Execution Summary</font></b><br/><br/>");
        f_out.println("<table " + classParam + "  cellspacing=\"0\" cellpadding=\"0\" width=\"91%\">"
                + "<thead><tr><th>Test Suite Name</th><th>" + "# Unique TestCases</th><th>"
                + "# Combinations</th> <th>" + "# Passed</th> <th>" + "# Failed</th> <th>"
                + "# Warning</th> <th>" + "# Skipped</th><th>" + "# Total</th> <th>"
                + "Success Rate</th> </tr> </thead>" + " <tbody> <tr><td><b>" + suiteName + "</b></td><td>"
                + total_unique_testcases + "</td><td>" + total_browser_combinations + "</td><td>"
                + suite_totalPassedMethods + "</td><td>" + suite_totalFailedMethods + "</td><td>"
                + suite_totalAutomationErrors + "</td><td>" + suite_totalSkippedMethods + "</td><td>"
                + (suite_totalPassedMethods + suite_totalFailedMethods + suite_totalSkippedMethods
                        + suite_totalAutomationErrors)
                + "</td><td>" + suite_passPercentage + " %" + "</td></tr></tbody></table>");

    }
    f_out.flush();

    f_out.println("<br/>");
    f_out.println("<p><b>Modulewise Execution Summary</b></p>");
    f_out.println(dashboardResults);
    //        if(!emailable){
    //        f_out.println("<br/><h4>Legend:</h4>");
    //        f_out.print("<ul>");
    //        f_out.println("<li>T: Unique Testcase</li>");
    //        f_out.println("<li>B: Unique Browser Combination</li>");
    //        f_out.print("</ul>");
    //        }else{
    f_out.println("<br/><br/><br/><br/>");
    //        }
    f_out.flush();
}

From source file:com.abiquo.nodecollector.domain.collectors.VirtualBoxCollector.java

/**
 * Parses the fileName to get the datastore name.
 * /*  w  w w.ja  va  2 s .com*/
 * @param fileName the file name to parse
 * @return the datastore directory
 */
private String getDatastoreFromFile(final String fileName) {
    int count = StringUtils.countMatches(fileName, "/");
    if (count == 1) {
        return "/";
    }
    int indexEndDirectory = fileName.lastIndexOf('/');
    return fileName.substring(0, indexEndDirectory);
}

From source file:com.activecq.samples.workflow.impl.LocalizedTagTitleExtractorProcessWorkflow.java

/**
 * Returns localized Tag Titles for all the ancestor tags to the tags supplied in "tagPaths"
 * <p/>/* w  w  w. j  a v  a  2  s  .  c o  m*/
 * Tags in
 *
 * @param tags
 * @param locale
 * @param tagManager
 * @return
 */
private List<String> tagsToUpstreamLocalizedTagTitles(Tag[] tags, Locale locale, TagManager tagManager) {
    List<String> localizedTagTitles = new ArrayList<String>();

    for (final Tag tag : tags) {
        String tagID = tag.getTagID();

        boolean isLast = false;

        int count = StringUtils.countMatches(tagID, PATH_DELIMITER);
        while (count >= MIN_TAG_DEPTH && count >= 0) {

            final Tag ancestorTag = tagManager.resolve(tagID);
            if (ancestorTag != null) {
                localizedTagTitles.add(getLocalizedTagTitle(ancestorTag, locale));
            }

            if (isLast) {
                break;
            }

            tagID = StringUtils.substringBeforeLast(tagID, PATH_DELIMITER);
            count = StringUtils.countMatches(tagID, PATH_DELIMITER);

            if (count <= 0) {
                isLast = true;
            }
        }
    }

    return localizedTagTitles;
}

From source file:com.clican.pluto.dataprocess.dpl.parser.impl.FunctionParserImpl.java

public Function parseFunction(String dpl, ProcessorContext context) throws DplParseException {
    if (!containFunction(dpl)) {
        return null;
    }//from  ww  w . ja v  a 2s.c o  m
    String copy = dpl;
    if (StringUtils.isEmpty(dpl)) {
        throw new DplParseException("??");
    }
    dpl = removeUnused(dpl);
    dpl = processPriority(dpl);
    if (!dpl.contains(START_KEYWORD) && !dpl.contains(END_KEYWORD)) {
        throw new DplParseException("?????'" + START_KEYWORD
                + "'" + PARAM_SPLIT_EXPR + "'" + END_KEYWORD + "'");
    }
    // if (log.isDebugEnabled()) {
    // log.debug("parse function[" + dpl.replaceAll("\n", "") + "]");
    // }
    try {
        String functionName = dpl.substring(0, dpl.indexOf(START_KEYWORD)).trim();
        if (StringUtils.isEmpty(functionName)) {
            int index = 0;
            int leftKey = 0;
            int rightRight = 0;
            while (index < dpl.length()) {
                String s = dpl.substring(index, index + 1);
                if (s.equals(START_KEYWORD)) {
                    leftKey++;
                }
                if (s.equals(END_KEYWORD)) {
                    rightRight++;
                }
                if (leftKey - rightRight == 1) {
                    Function function = null;
                    String[] params = new String[2];
                    if (s.equals("+")) {
                        function = new Plus();
                    } else if (s.equals("-")) {
                        function = new Minus();
                    } else if (s.equals("/")) {
                        function = new Divide();
                    } else if (s.equals("*")) {
                        function = new Multi();
                    } else if (s.equals("<")) {
                        function = new Less();
                    } else if (s.equals(">")) {
                        function = new Great();
                    } else if (s.equals("^")) {
                        function = new Pow();
                    } else if (s.equals("%")) {
                        function = new Mod();
                    } else {
                        index++;
                        continue;
                    }
                    String paramExpr = dpl.substring(dpl.indexOf(FunctionParserImpl.START_KEYWORD) + 1,
                            dpl.lastIndexOf(FunctionParserImpl.END_KEYWORD));
                    params[0] = paramExpr.substring(0, index - 1).trim();
                    params[1] = paramExpr.substring(index).trim();
                    String param = "";
                    List<Object> paramList = new ArrayList<Object>();
                    for (int i = 0; i < params.length; i++) {
                        if (StringUtils.isEmpty(param)) {
                            param = params[i];
                        } else {
                            param += "," + params[i];
                        }
                        int left = StringUtils.countMatches(param, START_KEYWORD);
                        int right = StringUtils.countMatches(param, END_KEYWORD);
                        boolean containOperation = FunctionOperation.containOperation(param);
                        if (left == 0 && right == 0 && !containOperation) {
                            paramList.add(param);
                            param = "";
                        } else if (left == right) {
                            paramList.add(this.parseFunction(param, context));
                            param = "";
                        } else if (i == params.length - 1) {
                            throw new DplParseException("?()?");
                        }
                    }
                    function.setExpr(copy);
                    function.setParams(paramList);
                    return function;
                }
                index++;
            }
            throw new DplParseException("?()?");
        } else {
            functionName = functionName.substring(0, 1).toUpperCase() + functionName.substring(1);
            String functionTrace = null;
            if (functionName.contains("=>")) {
                functionTrace = functionName.split("=>")[1];
                functionName = functionName.split("=>")[0];
            }
            Class<?> clazz = null;

            try {
                clazz = Class.forName(FUNCTION_PACKAGE + "." + functionName);
            } catch (ClassNotFoundException e) {
                for (String extPackage : extFunctionPackage) {
                    try {
                        clazz = Class.forName(extPackage + "." + functionName);
                    } catch (ClassNotFoundException ex) {

                    }
                }
                if (clazz == null) {
                    throw e;
                }
            }

            Function function = (Function) clazz.newInstance();
            function.setTrace(functionTrace);
            String paramExpr = dpl.substring(dpl.indexOf(FunctionParserImpl.START_KEYWORD) + 1,
                    dpl.lastIndexOf(FunctionParserImpl.END_KEYWORD));
            String[] params = paramExpr.split(PARAM_SPLIT_EXPR);
            String param = "";
            List<Object> paramList = new ArrayList<Object>();
            for (int i = 0; i < params.length; i++) {
                if (StringUtils.isEmpty(param)) {
                    param = params[i].trim();
                } else {
                    param += "," + params[i].trim();
                }
                int left = StringUtils.countMatches(param, START_KEYWORD);
                int right = StringUtils.countMatches(param, END_KEYWORD);
                boolean containOperation = FunctionOperation.containOperation(param);
                if (left == 0 && right == 0 && !containOperation) {
                    paramList.add(param);
                    param = "";
                } else if (left == right) {
                    paramList.add(this.parseFunction(param, context));
                    param = "";
                } else if (i == params.length - 1) {
                    throw new DplParseException("?()?");
                }
            }
            function.setParams(paramList);
            function.setExpr(copy);
            return function;
        }
    } catch (Exception e) {
        throw new DplParseException("expr[" + copy + "]", e);
    }

}

From source file:com.obomprogramador.tools.jqana.parsers.CycloListener.java

private int countSymbols(String originalText, String whatToFind) {
    return StringUtils.countMatches(originalText, whatToFind);
}