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

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

Introduction

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

Prototype

public static int countMatches(final CharSequence str, final char ch) 

Source Link

Document

Counts how many times the char appears in the given string.

A null or empty ("") String input returns 0 .

 StringUtils.countMatches(null, *)       = 0 StringUtils.countMatches("", *)         = 0 StringUtils.countMatches("abba", 0)  = 0 StringUtils.countMatches("abba", 'a')   = 2 StringUtils.countMatches("abba", 'b')  = 2 StringUtils.countMatches("abba", 'x') = 0 

Usage

From source file:com.kotcrab.vis.editor.ui.scene.entityproperties.NumberInputField.java

/** @param floatInput if true field fill allow to enter floats, if false only integers will be allowed */
public NumberInputField(FocusListener sharedFocusListener, ChangeListener sharedChangeListener,
        boolean floatInput) {
    addValidator(sharedFieldValidator);/*from w  w  w .ja v a2 s  .c  om*/

    //without disabling it, it would cause to set old values from new entities on switch
    setProgrammaticChangeEvents(false);

    addListener(sharedFocusListener);
    addListener(sharedChangeListener);
    setTextFieldFilter(new FieldFilter(floatInput));

    repeatTask = new TimerRepeatTask();

    addListener(new InputListener() {
        @Override
        public boolean keyTyped(InputEvent event, char character) {
            fire(new ChangeEvent());
            return false;
        }
    });

    addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            int matches = StringUtils.countMatches(getText(), "-");
            if (matches > 1) {
                event.cancel();
                return;
            }

            if (matches == 1 && getText().startsWith("-") == false) {
                event.cancel();
            }
        }
    });
}

From source file:net.mindengine.galen.specs.reader.page.StateObjectDefinition.java

private void addMultiObject(String objectName, Locator locator) {
    if (StringUtils.countMatches(objectName, "*") > 1) {
        throw new SyntaxException(UNKNOWN_LINE, "Incorrect object name: " + objectName);
    } else {/*  www  . j a  v a2 s . c om*/
        pageSpec.addMultiObject(objectName, locator);
    }
}

From source file:com.seleniumtests.it.core.TestSeleniumRobotTestListener.java

/**
 * Test that 2 tests (1 cucumber and 1 TestNG) are correctly executed in parallel
 * - result is OK/* w w  w  .  j  a v a  2 s.co m*/
 * - test names are OK
 * Check is done indirectly from the report files because there seems to be no way to check listener state
 * @param testContext
 * @throws Exception
 */
@Test(groups = { "it" })
public void testMultiThreadTests(ITestContext testContext) throws Exception {

    executeSubTest(5, new String[] { "com.seleniumtests.it.stubclasses.StubTestClass.testAndSubActions" },
            "core_3,core_4", "");

    String mainReportContent = FileUtils.readFileToString(new File(
            new File(SeleniumTestsContextManager.getGlobalContext().getOutputDirectory()).getAbsolutePath()
                    + File.separator + "SeleniumTestReport.html"));
    Assert.assertTrue(mainReportContent.contains(">core_3</a>"));
    Assert.assertTrue(mainReportContent.contains(">core_4</a>"));
    Assert.assertTrue(mainReportContent.contains(">testAndSubActions</a>"));

    // all 3 methods are OK
    Assert.assertEquals(StringUtils.countMatches(mainReportContent, "<i class=\"fa fa-circle circleSuccess\">"),
            3);
}

From source file:io.seldon.api.state.zk.ZkClientConfigHandler.java

private boolean isClientPath(String path) {
    // i.e. a path like /all_clients/testclient is one but /all_clients/testclient/mf is not
    return StringUtils.countMatches(path, "/") == 2;
}

From source file:MiGA.motifStats.java

public void refresh() {
    if (motif.contains("A")) {
        perA = (double) (mbp_len / motif.length()) * StringUtils.countMatches(motif, "A") / Globals.A * 100;
    }// w w  w  . j  av a2s. c om
    if (motif.contains("T")) {
        perT = (double) (mbp_len / motif.length()) * StringUtils.countMatches(motif, "T") / Globals.T * 100;
    }
    if (motif.contains("G")) {
        perG = (double) (mbp_len / motif.length()) * StringUtils.countMatches(motif, "G") / Globals.G * 100;
    }
    if (motif.contains("C")) {
        perC = (double) (mbp_len / motif.length()) * StringUtils.countMatches(motif, "C") / Globals.C * 100;
    }
}

From source file:com.indoqa.lang.util.URLStringUtils.java

/**
 * Calculate the "relativizer" of a path. E.g. <code>a/b/c</code> becomes <code>../../</code>. If a path doesn't start with a
 * slash, one is prepended.//from   w  w w  .  j a va2 s .co m
 * <p>
 * The implementation is null-safe. Passing null as input returns null as result.
 *
 * @param path The path to be relativized.
 * @return The relativizer.
 */
public static String relativizePath(final String path) {
    Validate.notNull(path, "A value for path is expected.");

    if (StringUtils.isBlank(path)) {
        return "";
    }

    String cleanedPath = path;
    if (cleanedPath.startsWith("/")) {
        cleanedPath = cleanedPath.substring(1);
    }

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < StringUtils.countMatches(cleanedPath, "/"); i++) {
        sb.append("../");
    }

    return sb.toString();
}

From source file:hammingcode.HammingCode.java

String addCheckBits(String str, String parity) {
    String codeWord = "";
    double noOfCheckBits = Math.log(str.length());
    noOfCheckBits /= Math.log(2);
    noOfCheckBits++;//from  w  w w .  j  a v  a  2 s . c o m
    for (int i = 0, j = 1; j <= str.length() + noOfCheckBits; j++) {
        if ((j & (j - 1)) == 0) {
            codeWord += "0";
        } else {
            codeWord += str.charAt(i);
            i++;
        }
    }
    str = codeWord;
    codeWord = "";
    for (int i = 0, j = 1; j <= str.length() + noOfCheckBits; j++) {
        if ((j & (j - 1)) == 0) {
            if (StringUtils.equalsIgnoreCase(parity, "even")) {
                if (StringUtils.countMatches(takeNthPower(str, j), "1") % 2 == 0) {
                    codeWord += "0";
                } else {
                    codeWord += "1";
                }
            } else if (StringUtils.equalsIgnoreCase(parity, "odd")) {
                if (StringUtils.countMatches(takeNthPower(str, j), "1") % 2 == 0) {
                    codeWord += "1";
                } else {
                    codeWord += "0";
                }
            }
        } else {
            codeWord += str.charAt(i);
            i++;
        }
    }
    return codeWord;
}

From source file:com.mycompany.instagramcredentialvalidation.LoginValidation.java

private void SetParameters(String param) {
    int count = StringUtils.countMatches(param, ",");
    if (count == 5) {
        String[] array = param.split(",");
        username = array[0];/*from w  w  w . j  av  a  2s  .  co m*/
        password = array[1];
        System.out.println("PASSSWORD " + password);
        ip = array[2];
        port = array[3];
        proxyUser = array[4];
        proxyPass = array[5];
    } else {
        result = false;
    }
}

From source file:com.seleniumtests.ut.core.TestLogActions.java

/**
 * Check that if a step accepts a variable number of arguments, they are replaced
 *//*ww w  .  java  2  s.  c o  m*/
@Test(groups = { "ut" })
public void testMultiplePassworkMasking() {

    testPage._setPasswords("someText", "someOtherText");
    TestStep step = TestLogging.getTestsSteps().get(TestLogging.getCurrentTestResult()).get(2);

    // all occurences of the password have been replaced
    Assert.assertFalse(step.toString().contains("someText"));
    Assert.assertFalse(step.toString().contains("someOtherText"));
    Assert.assertEquals(StringUtils.countMatches(step.toString(), "******"), 3);
}

From source file:eu.europa.ejusticeportal.dss.demo.web.tags.RequestUrlRelativeUrlTagStrategy.java

/**
 * @param reqUrl/*from w  w w.  j ava 2s . c o m*/
 *            the request URL relative to the context root
 * @return the depth in terms of number of directories from the context root
 */
protected static int getDepthFromRoot(String reqUrl) {
    return StringUtils.countMatches(reqUrl, "/");
}