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:org.klab.com.etl.Movies.java
public void readFile(String file, BufferedWriter bw) { int _n_ = 0;/*from w w w. j a v a 2s . c o m*/ int _r_ = 0; LineIterator it = null; String FILE_DATE = movieFileDate(file); try { it = FileUtils.lineIterator(new File(file), "UTF-8"); while (it.hasNext()) { String line = it.nextLine(); int amountOfTabsLine = StringUtils.countMatches(line, SEPARATOR); //This will decide the structure String fixedLine = fixLine(line); // do something with line // System.out.println("N:\t"+amountOfTabsLine+ "\t"+line); if (!fixedLine.isEmpty() && _n_ > 0) { String output = _n_ + "\t" + FILE_DATE + "\t" + amountOfTabsLine + "\t" + fixedLine; bw.write(output); bw.newLine(); _r_++; } _n_++; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { System.out.println("io > [" + _n_ + "][" + _r_ + "] > out"); LineIterator.closeQuietly(it); } }
From source file:org.ktc.soapui.maven.invoker.util.CheckBuildLog.java
public void assertLogFileContains(String expectedContent) { log("Expect to find content in the log file: " + expectedContent); int matchCount = StringUtils.countMatches(logFileContent, expectedContent); log("Found " + matchCount + " occurences"); if (matchCount < 1) { logAndFail("FAILED! Did not find expected content in the log file: " + expectedContent); }/*w w w . j a va 2s . c o m*/ }
From source file:org.ktc.soapui.maven.invoker.util.CheckBuildLog.java
public void assertLogFileContainsOneOf(String... expected) { log("Expect to find one of the following in the log file: " + ArrayUtils.toString(expected)); for (String string : expected) { int matchCount = StringUtils.countMatches(logFileContent, string); log(" Checking: " + string); log(" Found " + matchCount + " occurences"); if (matchCount > 0) { return; }//from ww w .java2 s. co m } logAndFail("FAILED! Did not find one of expected content in the log file"); }
From source file:org.ktc.soapui.maven.invoker.util.CheckBuildLog.java
public void assertLogFileContainsStrictly(String expectedContent, int expectedCount) { log("Expect to find content " + expectedCount + " times in the log file. Content: " + expectedContent); int matchCount = StringUtils.countMatches(logFileContent, expectedContent); log("Found " + matchCount + " occurences"); if (matchCount != expectedCount) { logAndFail("FAILED! Expect to find " + expectedCount + " times, found " + matchCount + " times. Expected content: " + expectedContent); }/* w w w .j a v a 2 s . c om*/ }
From source file:org.ktc.soapui.maven.invoker.util.CheckBuildLog.java
public void assertLogFileDoesNotContain(String content) { log("Expect not to find content in the log file: " + content); int matchCount = StringUtils.countMatches(logFileContent, content); log("Found " + matchCount + " occurences"); if (matchCount > 0) { logAndFail("FAILED! Found unexpected content in the log file: " + content); }//from w w w. j ava 2 s. com }
From source file:org.kuali.kfs.fp.batch.service.impl.ProcurementCardCreateDocumentServiceImpl.java
/** * Creates a ProcurementCardDocument from the List of transactions given. * * @param transactions List of ProcurementCardTransaction objects to be used for creating the document. * @return A ProcurementCardDocument populated with the transactions provided. *//* w ww . j a va2s . c om*/ protected ProcurementCardDocument createProcurementCardDocument(List transactions) { ProcurementCardDocument pcardDocument = null; try { // get new document from doc service pcardDocument = (ProcurementCardDocument) SpringContext.getBean(DocumentService.class) .getNewDocument(PROCUREMENT_CARD); List<CapitalAssetInformation> capitalAssets = pcardDocument.getCapitalAssetInformation(); for (CapitalAssetInformation capitalAsset : capitalAssets) { if (ObjectUtils.isNotNull(capitalAsset) && ObjectUtils.isNotNull(capitalAsset.getCapitalAssetInformationDetails())) { capitalAsset.setDocumentNumber(pcardDocument.getDocumentNumber()); } } ProcurementCardTransaction trans = (ProcurementCardTransaction) transactions.get(0); String errors = validateTransaction(trans); createCardHolderRecord(pcardDocument, trans); // for each transaction, create transaction detail object and then acct lines for the detail int transactionLineNumber = 1; KualiDecimal documentTotalAmount = KualiDecimal.ZERO; String errorText = ""; for (Iterator iter = transactions.iterator(); iter.hasNext();) { ProcurementCardTransaction transaction = (ProcurementCardTransaction) iter.next(); // create transaction detail record with accounting lines errorText += createTransactionDetailRecord(pcardDocument, transaction, transactionLineNumber); // update document total documentTotalAmount = documentTotalAmount.add(transaction.getFinancialDocumentTotalAmount()); transactionLineNumber++; } pcardDocument.getFinancialSystemDocumentHeader().setFinancialDocumentTotalAmount(documentTotalAmount); // PCDO Default Description //pcardDocument.getDocumentHeader().setDocumentDescription("SYSTEM Generated"); setupDocumentDescription(pcardDocument); // Remove duplicate messages from errorText String messages[] = StringUtils.split(errorText, "."); for (int i = 0; i < messages.length; i++) { int countMatches = StringUtils.countMatches(errorText, messages[i]) - 1; errorText = StringUtils.replace(errorText, messages[i] + ".", "", countMatches); } // In case errorText is still too long, truncate it and indicate so. Integer documentExplanationMaxLength = dataDictionaryService .getAttributeMaxLength(DocumentHeader.class.getName(), KFSPropertyConstants.EXPLANATION); if (documentExplanationMaxLength != null && errorText.length() > documentExplanationMaxLength.intValue()) { String truncatedMessage = " ... TRUNCATED."; errorText = errorText.substring(0, documentExplanationMaxLength - truncatedMessage.length()) + truncatedMessage; } pcardDocument.getDocumentHeader().setExplanation(errorText); } catch (WorkflowException e) { LOG.error("Error creating pcdo documents: " + e.getMessage(), e); throw new RuntimeException("Error creating pcdo documents: " + e.getMessage(), e); } return pcardDocument; }
From source file:org.kuali.kfs.module.bc.util.ImportRequestFileParsingHelper.java
/** * Checks for the correct number of field separators and text delimiters on line (either annual or monthly file). Does not check if the correct field separator and text delimiter are being used (form level validation should do this) * * @param lineToParse/*from w w w . j a v a 2 s . c o m*/ * @param fieldSeperator * @param textDelimiter * @param isAnnual * @return */ public static boolean isLineCorrectlyFormatted(String lineToParse, String fieldSeperator, String textDelimiter, boolean isAnnual) { int fieldSeparatorCount = StringUtils.countMatches(lineToParse, fieldSeperator); int expectedNumberOfSeparators = isAnnual ? 5 : 16; if (textDelimiter.equalsIgnoreCase(BCConstants.RequestImportTextFieldDelimiter.NOTHING.getDelimiter())) { if (isAnnual) { if (fieldSeparatorCount != 5) { return false; } } else { if (fieldSeparatorCount != 16) { return false; } } } else if (StringUtils.countMatches(lineToParse, textDelimiter) != 10) { return false; } else if (getEscapedFieldSeparatorCount(lineToParse, fieldSeperator, textDelimiter, isAnnual) == -1 || (fieldSeparatorCount - getEscapedFieldSeparatorCount(lineToParse, fieldSeperator, textDelimiter, isAnnual) != expectedNumberOfSeparators)) { return false; } return true; }
From source file:org.kuali.kfs.module.bc.util.ImportRequestFileParsingHelper.java
/** * Checks if a line of an annual file contains an escaped field separator (convience method to aid in file parsing) * Will not work correctly if text delimiters are not correctly placed in lineToParse (method does not check file formatting) * * @param lineToParse/* w ww . ja v a 2 s . co m*/ * @param fieldSeperator * @param textDelimiter * @return number of escaped separators or -1 if file is incorrectly formatted */ private static int getEscapedFieldSeparatorCount(String lineToParse, String fieldSeperator, String textDelimiter, boolean isAnnual) { int firstIndexOfTextDelimiter = 0; int nextIndexOfTextDelimiter = lineToParse.indexOf(textDelimiter, firstIndexOfTextDelimiter + 1); int expectedNumberOfSeparators = isAnnual ? 5 : 16; int expectedTextDelimitersCount = 10; int actualNumberOfTextDelimiters = StringUtils.countMatches(lineToParse, textDelimiter); int totalSeparatorsInLineToParse = StringUtils.countMatches(lineToParse, fieldSeperator); int escapedSeparatorsCount = 0; //line does not use text delimiters if (textDelimiter.equalsIgnoreCase(BCConstants.RequestImportTextFieldDelimiter.NOTHING.getDelimiter())) { return 0; } //line does not contain escaped field separators if (totalSeparatorsInLineToParse == expectedNumberOfSeparators) { return 0; } //line is incorrectly formatted if (actualNumberOfTextDelimiters != expectedTextDelimitersCount) { return -1; } for (int i = 0; i < expectedTextDelimitersCount / 2; i++) { String escapedString = lineToParse.substring(firstIndexOfTextDelimiter, nextIndexOfTextDelimiter); escapedSeparatorsCount += StringUtils.countMatches(escapedString, fieldSeperator); firstIndexOfTextDelimiter = lineToParse.indexOf(textDelimiter, nextIndexOfTextDelimiter + 1); nextIndexOfTextDelimiter = lineToParse.indexOf(textDelimiter, firstIndexOfTextDelimiter + 1); } return escapedSeparatorsCount; }
From source file:org.kuali.kfs.module.tem.batch.service.impl.PerDiemLoadServiceImpl.java
/** * complete the date string if the year is missing *///from w ww . j a v a2 s .c o m protected String completeDateString(String dateString, int effectiveYear) { if (StringUtils.isNotEmpty(dateString) && StringUtils.countMatches(dateString, TemConstants.DATE_FIELD_SEPARATOR) >= 2) { return dateString; } return dateString + TemConstants.DATE_FIELD_SEPARATOR + effectiveYear; }
From source file:org.kuali.kra.printing.PersonSignatureLocationHelper.java
/** * This method is to find the count of first character in the signature tag * @return//from ww w.j a va 2s . c o m */ protected int getCountMatchOfSignatureTagFirstCharacter() { String firstChar = Character.toString(getCurrentSignatureTag().charAt(0)); return StringUtils.countMatches(getCurrentSignatureTag(), firstChar); }