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:io.zinx.hamcrest.string.pattern.OccurrenceMatcher.java

@Override
protected boolean matchesSafely(String item) {
    int countInItem = StringUtils.countMatches(item, searchString);
    return count == countInItem;
}

From source file:com.formkiq.core.webflow.dialect.NewlineAttrProcessorTest.java

/**
 * testGetText()./*from  w  w w.  ja  v a  2  s.co m*/
 * @throws IOException IOException
 */
@Test
public void testGetText() throws IOException {
    // given
    String str = getResourceAsString("/scheduleb.txt");

    // when
    String result = this.p.getText(str);

    // then
    final int count = 4;
    assertEquals(count, StringUtils.countMatches(result, "<br />"));
}

From source file:ext.sns.auth.OAuth2Client.java

/**
 * ??URI?Map//from w  w  w. j a  va  2  s .com
 * 
 * @param uri ?URI
 * @return ?Map
 */
public static Map<String, String> getAuthBackParamByURI(String uri) {
    // ??URI1????&
    int countMatches = StringUtils.countMatches(uri, "?");
    if (countMatches > 1) {
        int firstIndex = uri.indexOf("?");

        StringBuilder uriBuilder = new StringBuilder(uri);
        for (int i = 0; i < countMatches - 1; ++i) {
            int start = uriBuilder.indexOf("?", firstIndex + 1);
            uriBuilder.replace(start, start + 1, "&");
        }
        uri = uriBuilder.toString();
    }

    String paramStr = uri.substring(uri.indexOf("?") + 1);

    Map<String, String> paramMap = new HashMap<String, String>();

    String[] pairArray = paramStr.split("&");
    for (String pair : pairArray) {
        String[] paramArray = pair.split("=");

        String val = paramArray.length == 2 ? paramArray[1] : "";
        paramMap.put(paramArray[0], val);
    }

    return paramMap;
}

From source file:MiGA.motifStats.java

public motifStats(String m, int r) {
    sd_clc = false;//from  w w  w  .  j  a  v a2  s. c om
    motif = m;
    count = 1;
    repeats = r;
    mbp_len = motif.length() * r;
    avg_len = (double) mbp_len / count;
    max_len = (int) mbp_len;
    avg_repeats = (double) repeats / count;

    if (motif.contains("A")) {
        perA = (double) (mbp_len / motif.length()) * StringUtils.countMatches(motif, "A") / mbp_len * 100;
    }
    if (motif.contains("T")) {
        perT = (double) (mbp_len / motif.length()) * StringUtils.countMatches(motif, "T") / mbp_len * 100;
    }
    if (motif.contains("G")) {
        perG = (double) (mbp_len / motif.length()) * StringUtils.countMatches(motif, "G") / mbp_len * 100;
    }
    if (motif.contains("C")) {
        perC = (double) (mbp_len / motif.length()) * StringUtils.countMatches(motif, "C") / mbp_len * 100;
    }

    lens = new ArrayList<Integer>();
    lens.add(r * m.length());
}

From source file:io.zinx.hamcrest.string.pattern.OccurrenceMatcher.java

@Override
protected void describeMismatchSafely(String item, Description mismatchDescription) {
    mismatchDescription.appendValue(item).appendText(" contains ")
            .appendValue(StringUtils.countMatches(item, searchString)).appendText(" occurrence(s) of ")
            .appendValue(searchString);/*w  ww .  j av  a 2  s .  co m*/
}

From source file:net.gtaun.wl.race.dialog.TrackScriptEditDialog.java

protected WlPageListDialog create(Player player, EventManager eventManager, AbstractDialog parent,
        RaceServiceImpl service, Track track) {
    LocalizedStringSet stringSet = service.getLocalizedStringSet();

    List<ListDialogItem> items = new ArrayList<>();
    for (ScriptType type : ScriptType.values()) {
        items.add(new ListDialogItem(() -> {
            String code = track.getScript(type);
            int lines = StringUtils.countMatches(code, "\n");
            return stringSet.format(player, "Dialog.TrackScriptEditDialog.Item", type.name(), lines,
                    code.length());/*from   w ww  .  j a  v  a 2 s.  c om*/
        }, (i) -> {
            player.playSound(1083);

            String title = stringSet.format(player, "Dialog.TrackScriptEditDialog.EventFormat", type.name());
            String code = track.getScript(type);
            new CodeEditorDialog(player, eventManager, i.getCurrentDialog(), service, title, code,
                    (newCode) -> {
                        player.playSound(1083);
                        track.setScript(type, newCode);
                    }).show();
        }));
    }

    return WlPageListDialog.create(player, eventManager).parentDialog(parent)
            .caption((d) -> stringSet.format(player, "Dialog.TrackScriptEditDialog.Caption", track.getName()))
            .items(items).build();
}

From source file:com.wavemaker.app.build.pages.PageMinFileUpdator.java

private static void validatePageMinFile(String string, String subString) {
    if (StringUtils.countMatches(string, subString) != 1) {
        throw new WMRuntimeException("Page resource update not supported");
    }/*  w  ww  .  j  a v  a  2 s  . c  o  m*/
}

From source file:de.knightsoftnet.mtwidgets.client.ui.widget.oracle.PhoneNumberUriRestOracle.java

@Override
protected boolean needSuggest(final String pentry) {
    return StringUtils.isNotEmpty(pentry) && StringUtils.countMatches(pentry, "-") < 2;
}

From source file:de.knightsoftnet.mtwidgets.client.ui.widget.oracle.PhoneNumberE123RestOracle.java

@Override
protected boolean needSuggest(final String pentry) {
    return StringUtils.isNotEmpty(pentry) && StringUtils.countMatches(pentry, " ") < 2
            && !StringUtils.contains(pentry, ')');
}

From source file:com.qq.tars.web.controller.notify.NotifyController.java

@RequestMapping(value = "server/api/server_notify_list", produces = { "application/json" })
@ResponseBody// w  ww  . j  av a2 s .  co m
public List<ServerNotifyView> serverNotifyList(@RequestParam(value = "tree_node_id") String treeNodeId,
        @RequestParam(value = "cur_page", required = false, defaultValue = "0") int curPage,
        @RequestParam(value = "page_size", required = false, defaultValue = "0") int pageSize)
        throws Exception {
    try {
        int count = StringUtils.countMatches(treeNodeId, '.');
        Preconditions.checkArgument(count == 1 || count == 4, "?%s?", "tree_node_id");
    } catch (IllegalArgumentException e) {
        throw new ServletRequestParameterException(e);
    }

    return notifyService.getServerNotifyList(treeNodeId, curPage, pageSize).stream()
            .map(notify -> mapper.map(notify, ServerNotifyView.class)).collect(Collectors.toList());
}