List of usage examples for org.apache.commons.lang StringUtils countMatches
public static int countMatches(String str, String sub)
Counts how many times the substring appears in the larger String.
From source file:com.sixrr.stockmetrics.utils.LineUtil.java
public static int countBlankLines(PsiElement element) { if (element instanceof PsiCompiledElement) { return 0; }// w w w . ja v a 2 s .co m final String text = element.getText(); final String lineSeparator = text.contains("\r") ? "\r" : "\n"; final int totalLinesCount = 1 + StringUtils.countMatches(text, lineSeparator); return totalLinesCount - countLines(text); }
From source file:com.itbeyond.common.EOTrackMe.java
public static void removeSentLines(String lines) { int WriteLock_Timeout = 10; while (WriteLock_Timeout > 0) { try {/*from w w w. j a v a2s .c o m*/ if (StringUtils.countMatches(lines, "|") == getLogFileLines()) { // Delete the log file EOTrackMe.getLogFile().delete(); } else { File logFile = EOTrackMe.getLogFile(); // We must remove already processed lines // As the file is appended String thisline; StringBuilder fullfile = new StringBuilder(); BufferedReader br = new BufferedReader(new FileReader(logFile), 8192); while ((thisline = br.readLine()) != null) { if (!StringUtils.contains(lines, thisline)) { fullfile.append(thisline + "\n"); } } br.close(); logFile.delete(); logFile.createNewFile(); FileOutputStream writer = new FileOutputStream(EOTrackMe.getLogFile(), false); BufferedOutputStream output = new BufferedOutputStream(writer); output.write(fullfile.toString().getBytes()); output.flush(); output.close(); } break; } catch (IOException e) { if (WriteLock_Timeout < 5) { Utilities.LogError("EOTrackMe.removeSentLines - Write Lock", e); } try { Thread.sleep(500); } catch (InterruptedException e1) { } WriteLock_Timeout -= 1; } } }
From source file:de.thischwa.pmcms.model.tool.PathComparator.java
@Override public int compare(String str1, String str2) { int count1 = StringUtils.countMatches(str1, "/"); int count2 = StringUtils.countMatches(str2, "/"); if (count1 == count2) return 0; if (count1 < count2) return 1; return -1;/*ww w . j a v a 2 s . c o m*/ }
From source file:cern.c2mon.shared.rule.MultipleReturnValueRuleExpression.java
/** * @return True if the rule is a {@link MultipleReturnValueRuleExpression} * @see http://issues/browse/TIMS-839//from w w w . j a v a 2 s .co m * * @param rule the rule to be checked */ public static boolean isMultipleReturnValueExpression(final String rule) { final int bracketsCount = StringUtils.countMatches(rule.toString(), "["); return bracketsCount > 1; }
From source file:com.bazaarvoice.jless.ast.node.LineBreakNode.java
public LineBreakNode(String text) { _lineBreaks = StringUtils.countMatches(text, "\n"); }
From source file:com.kstenschke.shifter.utils.UtilsTextual.java
/** * @param str String to be checked * @return boolean Is the given string is a comma separated list? *//*from ww w .ja v a2 s . c o m*/ public static boolean isCommaSeparatedList(String str) { if (!str.contains(",")) { return false; } // If the string is quoted: detect whether items are quoted each // => there must be (amountCommas+1)*2 quotes altogether // Ex: "a","b" => 1 comma, 4 quotes // "a","b","c","d" => 3 commas, 8 quotes // Otherwise it should be treated as a quoted string and not as a list. if (isWrappedIntoQuotes(str)) { String quoteChar = str.substring(0, 1); int amountQuotes = StringUtils.countMatches(str, quoteChar); int amountCommas = StringUtils.countMatches(str, ","); if (amountQuotes != (amountCommas + 1) * 2) { return false; } } return true; }
From source file:com.bazaarvoice.jolt.common.pathelement.StarSinglePathElement.java
public StarSinglePathElement(String key) { super(key);//from w ww. ja va 2 s.co m if (StringUtils.countMatches(key, "*") != 1) { throw new IllegalArgumentException("StarSinglePathElement should only have one '*' in its key."); } else if ("*".equals(key)) { throw new IllegalArgumentException("StarSinglePathElement should have a key that is just '*'."); } if (key.startsWith("*")) { prefix = ""; suffix = key.substring(1); } else if (key.endsWith("*")) { prefix = key.substring(0, key.length() - 1); suffix = ""; } else { String[] split = key.split("\\*"); prefix = split[0]; suffix = split[1]; } }
From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigUtil.java
public int numbersOfPipelin() { String output = contents.read(); return StringUtils.countMatches(output, "</pipeline>"); }
From source file:de.tudarmstadt.ukp.dkpro.tc.features.pair.core.ngram.meta.ComboUtils.java
/** * Get combinations of ngrams from a pair of documents. * //from w w w . j a v a2 s. com * @param document1NGrams ngrams from document 1 * @param document2NGrams ngrams from document 2 * @param minN minimum size for a new combined ngram * @param maxN max size for a new combined ngram * @param ngramUseSymmetricalCombos whether or not to return view-neutral ngrams * @return combinations of ngrams */ public static FrequencyDistribution<String> getCombinedNgrams(FrequencyDistribution<String> document1NGrams, FrequencyDistribution<String> document2NGrams, int minN, int maxN, boolean ngramUseSymmetricalCombos) { FrequencyDistribution<String> documentComboNGrams = new FrequencyDistribution<String>(); for (String ngram1 : document1NGrams.getKeys()) { int ngram1size = StringUtils.countMatches(ngram1, NGramUtils.NGRAM_GLUE) + 1; for (String ngram2 : document2NGrams.getKeys()) { int ngram2size = StringUtils.countMatches(ngram2, NGramUtils.NGRAM_GLUE) + 1; if (ngram1size + ngram2size >= minN && ngram1size + ngram2size <= maxN) { //final feature value, binary or count, is controlled in the FE long value = document1NGrams.getCount(ngram1) * document2NGrams.getCount(ngram2); String comboNgram = ngram1 + JOINT + ngram2; documentComboNGrams.addSample(comboNgram, value); if (ngramUseSymmetricalCombos) { comboNgram = ngram2 + JOINT + ngram1; documentComboNGrams.addSample(comboNgram, value); } } } } return documentComboNGrams; }
From source file:blackboard.sonar.plugins.css.node.Node.java
public int getLinesOfCode() { return StringUtils.countMatches(code, "\n"); }