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.rapidcontext.app.web.StorageWebService.java
/** * Returns the relative path to reverse the specified path. This * method will add an "../" part for each directory in the * current path so that site-relative links can be created * easily.//w w w. jav a 2 s . c o m * * @param path the path to reverse * * @return the relative reversed path */ private String relativeBackPath(String path) { int count = StringUtils.countMatches(path, "/"); return StringUtils.repeat("../", count); }
From source file:org.rassee.omniture.hadoop.mapreduce.OmnitureDataFileRecordReader.java
@Override /**//from w w w . j a v a 2 s . c o m * Reads the next record in the split. * @throws IOException * @throws InterruptedException */ public boolean nextKeyValue() throws IOException, InterruptedException { String line; if (key == null) { key = new LongWritable(); } key.set(pos); if (value == null) { value = new Text(); } int bytesRead = 0; int countTabs = 0; // Stay within the split while (pos < end) { bytesRead = lineReader.readLine(value, maxLineLength, Math.max((int) Math.min(Integer.MAX_VALUE, end - pos), maxLineLength)); // If we didn't read anything, then we're done if (bytesRead == 0) { break; } // Modify the line that's returned by the EscapedLineReader so that the tabs won't be an issue to split on // Remember that in Java a \\\\ within a string regex = one backslash line = value.toString().replaceAll("\\\\\t", "").replaceAll("\\\\(\n|\r|\r\n)", ""); countTabs = StringUtils.countMatches(line, "\t"); value.set(line); // Move the position marker pos += bytesRead; // Ensure that we didn't read more than we were supposed to and that we don't have a bogus line which should be skipped if (bytesRead < maxLineLength && countTabs == numberOfFields) { break; } if (numberOfFields != countTabs) { // TODO: Implement counters to track number of skipped lines, possibly only available via map and reduce functions LOG.warn("Skipped line at position " + (pos - bytesRead) + " with incorrect number of fields (expected " + numberOfFields + " but found " + countTabs + ")"); } else { // Otherwise the line is too long and we need to skip this line LOG.warn("Skipped line of size " + bytesRead + " at position " + (pos - bytesRead)); } } // Check to see if we actually read a line and return appropriate boolean if (bytesRead == 0 || countTabs != numberOfFields) { key = null; value = null; return false; } else { return true; } }
From source file:org.rassee.omniture.pig.OmnitureDataLoader.java
public OmnitureDataLoader() { schema = DefaultSchemaGenerator.getInstance().generatePigSchema(); fieldCount = StringUtils.countMatches(schema, ","); }
From source file:org.rassee.omniture.pig.OmnitureDataLoader.java
public OmnitureDataLoader(String localSchemaJsonFile) throws ClassNotFoundException, IllegalAccessException, InstantiationException, IOException { schema = new LocalFileBasedSchemaGenerator(localSchemaJsonFile).generatePigSchema(); fieldCount = StringUtils.countMatches(schema, ","); }
From source file:org.rassee.omniture.pig.TestLocalFileBasedSchemaGenerator.java
@Test public void testSchema1() throws FileNotFoundException { SchemaGenerator generator = new LocalFileBasedSchemaGenerator("src/test/resources/schema1.json"); assertEquals(generator.getColumnHeadersDelimiter(), "\t"); assertEquals(generator.generatePigSchema().split(",").length, 554); assertEquals(generator.getColumnHeaders().split("\t").length, 554); assertEquals(StringUtils.countMatches(generator.generatePigSchema(), "long"), 60); }
From source file:org.redpill.alfresco.repo.findwise.processor.DefaultVerifierProcessor.java
public void setFileExtensions(String fileExtensions) { this.fileExtensions = new HashSet<String>(); String[] split = fileExtensions.split(","); for (String ext : split) { if (LOG.isTraceEnabled()) { LOG.trace("Allowing file extension: " + ext); }/*from w w w.j a v a2s.co m*/ this.fileExtensions.add(ext.trim().toLowerCase()); } if (split.length <= StringUtils.countMatches(fileExtensions, ",")) { this.fileExtensions.add(""); if (LOG.isTraceEnabled()) { LOG.trace("Allowing empty file extension"); } } }
From source file:org.richfaces.tests.showcase.push.TestPushTopicsContext.java
/** * Check very simply whether uuid is correct, it means whether it has 36 characters and that contains 4 hyphens *//* w w w . j av a 2s . c om*/ private void checkTheUuid(TextRetriever uuidRetriever) { String uuid = uuidRetriever.getValue(); assertEquals(uuid.length(), 36, "The length of uuid is wrong!"); assertEquals(StringUtils.countMatches(uuid, "-"), 4, "Wrong uuid, there should be 4 hyphens"); }
From source file:org.roche.antibody.ui.abstractgraph.RNARealizer.java
public void initFromMap() { try {//from w ww . j a v a2 s .c om setShapeType(PARALLELOGRAM); setFillColor(Color.GREEN); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); RNA mol = (RNA) getNode().getGraph().getDataProvider(AbConst.NODE_TO_SEQUENCE_KEY).get(getNode()); if (mol != null) { // JF 2014-06-16: Changed label to number of nucleid acids + bp (base pair) int countNucleidAcids = StringUtils.countMatches(mol.getName(), "("); StringBuilder sb = new StringBuilder(); sb.append("NN ("); sb.append(countNucleidAcids); sb.append("bp)"); setLabelText(sb.toString()); initialized = true; } } catch (NullPointerException e) { // Not yet ready for initialization } }
From source file:org.sakaiproject.content.impl.BaseContentService.java
/** * Hide imported content -- SAK-23305//www . j a va 2 s .co m * @param edit Object either a ContentResourceEdit or ContentCollectionEdit object */ private void hideImportedContent(Object edit) { if (m_serverConfigurationService.getBoolean("content.import.hidden", false)) { ContentResourceEdit resource = null; ContentCollectionEdit collection = null; String containingCollectionId = null; if (edit instanceof ContentResourceEdit) { resource = (ContentResourceEdit) edit; containingCollectionId = resource.getContainingCollection().getId(); } else if (edit instanceof ContentCollectionEdit) { collection = (ContentCollectionEdit) edit; containingCollectionId = collection.getContainingCollection().getId(); } if (resource != null || collection != null) { /* * If this is "reuse content" during worksite setup, the site collection at this time is * /group/!admin/ for all content including ones in the folders, so count how many "/" in * the collection ID. If <= 3, then it's a top-level item and needs to be hidden. */ int slashcount = StringUtils.countMatches(containingCollectionId, "/"); if (slashcount <= 3) { if (resource != null) { resource.setHidden(); } else if (collection != null) { collection.setHidden(); } } } } }
From source file:org.schedoscope.metascope.index.model.SolrQueryResultEntity.java
public int getSize() { int size = 0; for (Entry<String, List<String>> e : highlightings.entrySet()) { if (excludedFromCount(e.getKey())) { for (String match : e.getValue()) { size += StringUtils.countMatches(match, "<b>"); }/* w w w . j a v a 2s . c om*/ } } return size; }