List of usage examples for org.apache.commons.lang3 StringUtils countMatches
public static int countMatches(final CharSequence str, final char ch)
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
From source file:com.plotsquared.iserver.files.FileSystem.java
/** * Get a path from a string/*from ww w . ja va 2 s . c om*/ * @param parent Parent path (folder), use {@link #getPath(String)} to access files within the core folder * @param rawPath The raw path to the file (relative to the parent) * @return The created path * @throws IllegalPathException If the path tries to access a file outside of the allowed scope (such as ../) */ public Path getPath(final Path parent, String rawPath) throws IllegalPathException { final String[] parts = rawPath.split("((?<=/)|(?=/))"); if (parts.length < 1) { return corePath; } if (parts[0].equals(".") || parts[0].equals("/")) { if (parts.length >= 2 && parts[1].equals("/")) { rawPath = rawPath.substring(2); } else { rawPath = rawPath.substring(1); } } for (final String part : parts) { if (StringUtils.countMatches(part, '.') > 1) { throw new IllegalPathException(rawPath); } } final String lastPart = parts[parts.length - 1]; if (parent.subPaths == null) { parent.loadSubPaths(); } if (parent.subPaths.containsKey(rawPath)) { return parent.subPaths.get(rawPath); } return new Path(this, parent.toString() + rawPath, lastPart.indexOf('.') == -1); }
From source file:io.cloudslang.lang.systemtests.flows.DataFlowTest.java
@Test public void testBindingsFlow() throws Exception { URI resource = getClass().getResource("/yaml/system-flows/bindings_flow.yaml").toURI(); URI operations = getClass().getResource("/yaml/system-flows/binding_flow_op.sl").toURI(); SlangSource dep = SlangSource.fromFile(operations); Set<SlangSource> path = Sets.newHashSet(dep); CompilationArtifact compilationArtifact = slang.compile(SlangSource.fromFile(resource), path); Map<String, Value> userInputs = new HashMap<>(); userInputs.put("base_input", ValueFactory.create(">")); Map<String, StepData> steps = triggerWithData(compilationArtifact, userInputs, SYSTEM_PROPERTIES) .getSteps();// w ww. java 2 s. c o m Map<String, Serializable> flowOutputs = steps.get(EXEC_START_PATH).getOutputs(); String finalOutput = (String) flowOutputs.get("final_output"); Assert.assertEquals("some of the inputs or outputs were not bound correctly", 13, finalOutput.length()); Assert.assertEquals("some of the inputs were not bound correctly", 6, StringUtils.countMatches(finalOutput, ">")); Assert.assertEquals("some of the outputs were not bound correctly", 5, StringUtils.countMatches(finalOutput, "<")); Assert.assertEquals("some of the results were not bound correctly", 2, StringUtils.countMatches(finalOutput, "|")); }
From source file:com.evolveum.midpoint.schema.parser.TestParseScriptOutput.java
@Test public void testNamespaces() throws Exception { String file = MiscUtil.readFile(getFile()); RootXNode xnode = getPrismContext().parserFor(file).parseToXNode(); System.out.println("XNode:\n" + xnode.debugDump()); String serialized = getPrismContext().xmlSerializer().serialize(xnode); System.out.println("XML: " + serialized); final String common_3 = "http://midpoint.evolveum.com/xml/ns/public/common/common-3"; int count = StringUtils.countMatches(serialized, common_3); assertEquals("Wrong # of occurrences of '" + common_3 + "' in serialized form", 2, count); }
From source file:cpcc.vvrte.services.js.JavascriptWorker.java
/** * @param vehicle the Virtual Vehicle.//from w w w .j a va 2 s . c o m * @param useContinuation true if the available continuation data should be applied. * @param logger the application logger. * @param serviceResources the service resources instance. * @param allowedClassesRegex the additionally allowed class names as a regular expression. * @throws IOException in case of errors. */ public JavascriptWorker(VirtualVehicle vehicle, boolean useContinuation, Logger logger, ServiceResources serviceResources, Set<String> allowedClassesRegex) throws IOException { this.logger = logger; this.serviceResources = serviceResources; this.allowedClassesRegex = allowedClassesRegex; this.vehicle = vehicle; workerState = VirtualVehicleState.INIT; if (useContinuation && vehicle.getContinuation() != null) { snapshot = vehicle.getContinuation(); } else { String apiScript = loadApiScript(); scriptStartLine = StringUtils.countMatches(apiScript, "\n") + 1; String code = vehicle.getCode(); script = StringUtils.isNotBlank(code) ? "(function(){ " + apiScript + "\n" + code.replace("\\n", "\n") + "\n})();" : null; } }
From source file:gr.abiss.calipso.model.base.AuditableResource.java
@PreUpdate @PrePersist/*w ww .j a va 2 s . c om*/ public void normalizePath() throws UnsupportedEncodingException { // set path if (this.getPath() == null) { StringBuffer path = new StringBuffer(); if (this.getParent() != null) { path.append(this.getParent().getPath()); } path.append(getPathSeparator()); path.append(this.getName()); this.setPath(path.toString()); } // set path level Integer pathLevel = StringUtils.countMatches(this.getPath(), getPathSeparator()); this.setPathLevel(pathLevel.shortValue()); }
From source file:it.uniud.ailab.dcore.annotation.annotators.RawTdidfAnnotator.java
private double tf(String docId, String term) { double result = StringUtils.countMatches(documents.get(docId), term); return result / docLengths.get(docId); }
From source file:dk.dma.db.cassandra.CassandraConnection.java
private static InetSocketAddress connectionPointToInetAddress(String connectionPoint) { InetSocketAddress inetSocketAddress; if (StringUtils.countMatches(connectionPoint, ":") == 1) { String[] split = connectionPoint.split(":"); String ipv4 = split[0];//from w w w . j av a 2 s .c o m Integer port = Integer.parseInt(split[1]); inetSocketAddress = new InetSocketAddress(ipv4, port); } else { inetSocketAddress = new InetSocketAddress(connectionPoint, 9042 /* default port */); } return inetSocketAddress; }
From source file:de.uni.bremen.monty.moco.util.MontyJar.java
private MontyResource[] getSubResources(boolean showFiles) { ArrayList<MontyResource> list = new ArrayList<>(); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry x = entries.nextElement(); if (x.getName().startsWith(jarEntry.getName())) { String substring = x.getName().substring(jarEntry.getName().length()); if (!substring.equals("")) { if (showFiles == substring.contains("/")) { if (!showFiles || StringUtils.countMatches(substring, "/") == 1 && substring.indexOf("/") == substring.length() - 1) { list.add(new MontyJar(jarFile, x)); }/*from www . j a va2 s. co m*/ } } } } MontyResource[] montyResources = list.toArray(new MontyResource[list.size()]); Arrays.sort(montyResources, comparator); return montyResources; }
From source file:info.rmapproject.api.service.ResourceApiServiceTestIT.java
/** * Test the RMap Resource RDF stmts API call *//*from w ww. j a va2 s .c om*/ @Test public void getRMapResourceRdfStmts() throws Exception { Response response = null; //create 1 disco RMapDiSCO rmapDisco = TestUtils.getRMapDiSCO(TestFile.DISCOA_XML); String discoURI = rmapDisco.getId().toString(); assertNotNull(discoURI); rmapService.createDiSCO(rmapDisco, requestEventDetails); HttpHeaders httpheaders = mock(HttpHeaders.class); UriInfo uriInfo = mock(UriInfo.class); MultivaluedMap<String, String> params = new MultivaluedHashMap<String, String>(); params.add(Constants.LIMIT_PARAM, "2"); List<MediaType> mediatypes = new ArrayList<MediaType>(); mediatypes.add(MediaType.APPLICATION_XML_TYPE); when(uriInfo.getQueryParameters()).thenReturn(params); when(httpheaders.getAcceptableMediaTypes()).thenReturn(mediatypes); response = resourceApiService.apiGetRMapResourceTriples(httpheaders, discoURI, uriInfo); assertNotNull(response); String body = response.getEntity().toString(); assertEquals(303, response.getStatus()); assertTrue(body.contains("page number")); URI location = response.getLocation(); MultiValueMap<String, String> parameters = UriComponentsBuilder.fromUri(location).build().getQueryParams(); String untildate = parameters.getFirst(Constants.UNTIL_PARAM); //check page 2 just has one statement params.add(Constants.PAGE_PARAM, "1"); params.add(Constants.UNTIL_PARAM, untildate); response = resourceApiService.apiGetRMapResourceTriples(httpheaders, discoURI, uriInfo); assertEquals(200, response.getStatus()); body = response.getEntity().toString(); int numMatches = StringUtils.countMatches(body, "xmlns="); assertEquals(2, numMatches); }
From source file:io.wcm.testing.mock.aem.MockPage.java
@Override public int getDepth() { if (StringUtils.equals("/", this.resource.getPath())) { return 0; } else {/* ww w . ja v a 2 s. c o m*/ return StringUtils.countMatches(this.resource.getPath(), "/"); } }