List of usage examples for org.springframework.util StringUtils countOccurrencesOf
public static int countOccurrencesOf(String str, String sub)
From source file:de.uzk.hki.da.cb.CheckFormatsActionTest.java
/** * Test that objects format lists are correct. * * @throws FileNotFoundException the file not found exception * @throws IOException Signals that an I/O exception has occurred. * @throws SubsystemNotAvailableException *///from w w w . ja v a 2 s.co m @Test public void testThatObjectsFormatListsAreCorrect() throws FileNotFoundException, IOException, SubsystemNotAvailableException { action.implementation(); assertThat(o.getMost_recent_formats().toString()).contains("fmt/353"); assertThat(o.getMost_recent_formats().toString()).contains("fmt/5"); assertThat(StringUtils.countOccurrencesOf(o.getMost_recent_formats().toString(), "fmt/353")).isEqualTo(1); assertThat(StringUtils.countOccurrencesOf(o.getMost_recent_formats().toString(), "fmt/5")).isEqualTo(1); assertThat(o.getOriginal_formats().toString()).contains("fmt/43"); assertThat(StringUtils.countOccurrencesOf(o.getOriginal_formats().toString(), "fmt/43")).isEqualTo(1); assertThat(o.getOriginal_formats().toString()).contains("fmt/5"); assertThat(StringUtils.countOccurrencesOf(o.getOriginal_formats().toString(), "fmt/5")).isEqualTo(1); }
From source file:de.uzk.hki.da.cb.CheckFormatsActionTest.java
/** * Test that objects codec lists are correct. * * @throws FileNotFoundException the file not found exception * @throws IOException Signals that an I/O exception has occurred. * @throws SubsystemNotAvailableException *//*from ww w . ja va2s . c o m*/ @Test public void testThatObjectsCodecListsAreCorrect() throws FileNotFoundException, IOException, SubsystemNotAvailableException { action.implementation(); assertThat(o.getMostRecentSecondaryAttributes().toString()).contains("cinepak"); assertThat(StringUtils.countOccurrencesOf(o.getMostRecentSecondaryAttributes().toString(), "cinepak")) .isEqualTo(1); }
From source file:de.uzk.hki.da.cb.CheckFormatsActionTest.java
/** * Test that objects formats lists are correct with deltas. * * @throws FileNotFoundException the file not found exception * @throws IOException Signals that an I/O exception has occurred. * @throws SubsystemNotAvailableException *//* ww w . j av a2 s. c o m*/ @Test public void testThatObjectsFormatsListsAreCorrectWithDeltas() throws FileNotFoundException, IOException, SubsystemNotAvailableException { Package aipPackage = new Package(); aipPackage.setName("1"); o.getPackages().add(aipPackage); action.implementation(); assertThat(o.getMost_recent_formats().toString()).contains("fmt/353"); assertThat(StringUtils.countOccurrencesOf(o.getMost_recent_formats().toString(), "fmt/353")).isEqualTo(1); assertThat(o.getMost_recent_formats().toString()).contains("fmt/5"); assertThat(StringUtils.countOccurrencesOf(o.getMost_recent_formats().toString(), "fmt/5")).isEqualTo(1); assertThat(o.getOriginal_formats().toString()).contains("fmt/43"); assertThat(o.getOriginal_formats().toString()).contains("fmt/5"); assertThat(o.getOriginal_formats().toString()).contains("x-fmt/384"); assertThat(StringUtils.countOccurrencesOf(o.getOriginal_formats().toString(), "fmt/43")).isEqualTo(1); assertThat(StringUtils.countOccurrencesOf(o.getOriginal_formats().toString(), "fmt/5")).isEqualTo(1); assertThat(StringUtils.countOccurrencesOf(o.getOriginal_formats().toString(), "x-fmt/384")).isEqualTo(1); }
From source file:de.uzk.hki.da.cb.CheckFormatsActionTest.java
/** * Test that objects codec lists are correct with deltas. * * @throws FileNotFoundException the file not found exception * @throws IOException Signals that an I/O exception has occurred. * @throws SubsystemNotAvailableException *//*from w w w . ja va 2 s . co m*/ @Test public void testThatObjectsCodecListsAreCorrectWithDeltas() throws FileNotFoundException, IOException, SubsystemNotAvailableException { Package aipPackage = new Package(); aipPackage.setName("1"); o.getPackages().add(aipPackage); action.implementation(); assertThat(o.getMostRecentSecondaryAttributes().toString()).contains("cinepak"); assertThat(StringUtils.countOccurrencesOf(o.getMostRecentSecondaryAttributes().toString(), "cinepak")) .isEqualTo(1); }
From source file:gda.data.metadata.NXMetaDataProvider.java
public String concatenateKeyAndValueForListAsString(String fmt, String delimiter) { String concatenated = ""; int sanityCheck = StringUtils.countOccurrencesOf(fmt, "%s"); System.out.println("***sanityCheck = " + sanityCheck); if (sanityCheck == 2) { for (Entry<String, Object> e : metaTextualMap.entrySet()) { // concatenated += "," + e.getKey() + ":" + e.getValue(); concatenated += String.format(fmt, e.getKey(), e.getValue()); concatenated += delimiter;//from w w w . j a v a 2 s . co m } // remove the unnecessary last delimiter concatenated = concatenated.substring(0, concatenated.length() - 1); } else { String defaultFmt = "%s:%s"; String defaultDelimiter = ","; logger.warn("Bad input format: " + "\"" + fmt + "\"" + " is " + "replaced by default format: " + "\"" + defaultFmt + "\""); concatenated = concatenateKeyAndValueForListAsString(defaultFmt, defaultDelimiter); } // remove the unnecessary last delimiter, if present // if ( concatenated.lastIndexOf(delimiter)==(concatenated.length()-1)){ // concatenated = concatenated.substring(0, concatenated.length()-1); // } return concatenated; }
From source file:org.eclipse.gemini.blueprint.extender.support.internal.ConfigUtils.java
public static boolean matchExtenderVersionRange(Bundle bundle, String header, Version versionToMatch) { Assert.notNull(bundle);//from ww w. j ava 2 s. c o m // get version range String range = bundle.getHeaders().get(header); boolean trace = log.isTraceEnabled(); // empty value = empty version = * if (!StringUtils.hasText(range)) return true; if (trace) log.trace("discovered " + header + " header w/ value=" + range); // do we have a range or not ? range = StringUtils.trimWhitespace(range); // a range means one comma int commaNr = StringUtils.countOccurrencesOf(range, COMMA); // no comma, no intervals if (commaNr == 0) { Version version = Version.parseVersion(range); return versionToMatch.equals(version); } if (commaNr == 1) { // sanity check if (!((range.startsWith(LEFT_CLOSED_INTERVAL) || range.startsWith(LEFT_OPEN_INTERVAL)) && (range.endsWith(RIGHT_CLOSED_INTERVAL) || range.endsWith(RIGHT_OPEN_INTERVAL)))) { throw new IllegalArgumentException("range [" + range + "] is invalid"); } boolean equalMin = range.startsWith(LEFT_CLOSED_INTERVAL); boolean equalMax = range.endsWith(RIGHT_CLOSED_INTERVAL); // remove interval brackets range = range.substring(1, range.length() - 1); // split the remaining string in two pieces String[] pieces = StringUtils.split(range, COMMA); if (trace) log.trace("discovered low/high versions : " + ObjectUtils.nullSafeToString(pieces)); Version minVer = Version.parseVersion(pieces[0]); Version maxVer = Version.parseVersion(pieces[1]); if (trace) log.trace("comparing version " + versionToMatch + " w/ min=" + minVer + " and max=" + maxVer); boolean result = true; int compareMin = versionToMatch.compareTo(minVer); if (equalMin) result = (result && (compareMin >= 0)); else result = (result && (compareMin > 0)); int compareMax = versionToMatch.compareTo(maxVer); if (equalMax) result = (result && (compareMax <= 0)); else result = (result && (compareMax < 0)); return result; } // more then one comma means incorrect range throw new IllegalArgumentException("range [" + range + "] is invalid"); }
From source file:org.eclipse.gemini.blueprint.io.OsgiBundleResourcePatternResolver.java
/** * Searches each level inside the bundle for entries based on the search strategy chosen. * // ww w. j av a2 s . co m * @param bundle the bundle to do the lookup * @param fullPattern matching pattern * @param dir directory inside the bundle * @param result set of results (used to concatenate matching sub dirs) * @param searchType the search strategy to use * @throws IOException */ private void doRetrieveMatchingBundleEntries(Bundle bundle, String fullPattern, String dir, Set<Resource> result, int searchType) throws IOException { Enumeration<?> candidates; switch (searchType) { case OsgiResourceUtils.PREFIX_TYPE_NOT_SPECIFIED: case OsgiResourceUtils.PREFIX_TYPE_BUNDLE_SPACE: // returns an enumeration of URLs candidates = bundle.findEntries(dir, null, false); break; case OsgiResourceUtils.PREFIX_TYPE_BUNDLE_JAR: // returns an enumeration of Strings candidates = bundle.getEntryPaths(dir); break; case OsgiResourceUtils.PREFIX_TYPE_CLASS_SPACE: // returns an enumeration of URLs throw new IllegalArgumentException("class space does not support pattern matching"); default: throw new IllegalArgumentException("unknown searchType " + searchType); } // entries are relative to the root path - miss the leading / if (candidates != null) { boolean dirDepthNotFixed = (fullPattern.indexOf(FOLDER_WILDCARD) != -1); while (candidates.hasMoreElements()) { Object path = candidates.nextElement(); String currPath; if (path instanceof String) currPath = handleString((String) path); else currPath = handleURL((URL) path); if (!currPath.startsWith(dir)) { // Returned resource path does not start with relative // directory: // assuming absolute path returned -> strip absolute path. int dirIndex = currPath.indexOf(dir); if (dirIndex != -1) { currPath = currPath.substring(dirIndex); } } if (currPath.endsWith(FOLDER_SEPARATOR) && (dirDepthNotFixed || StringUtils.countOccurrencesOf(currPath, FOLDER_SEPARATOR) < StringUtils .countOccurrencesOf(fullPattern, FOLDER_SEPARATOR))) { // Search subdirectories recursively: we manually get the // folders on only one level doRetrieveMatchingBundleEntries(bundle, fullPattern, currPath, result, searchType); } if (getPathMatcher().match(fullPattern, currPath)) { if (path instanceof URL) result.add(new UrlContextResource((URL) path, currPath)); else result.add(new OsgiBundleResource(bundle, currPath)); } } } }
From source file:org.openflamingo.engine.handler.HdfsArtifactLoader.java
@Override public String load(String filename) { String actionBasePath = ActionBasePathGenerator.getActionBasePath(context.getCurrentActionContext()); String jarPath = actionBasePath + "/jars"; String temporaryPath = FileUtils.getFilename(filename); // Maven Artifact? Maven Repository? . if (StringUtils.countOccurrencesOf(filename, ":") == 2) { String mavenUrl = DefaultHandler.getFlamingoConf("maven.repository.url"); String[] strings = org.apache.commons.lang.StringUtils.splitPreserveAllTokens(filename, ":"); return MavenArtifactLoader.downloadArtifactFromRepository(strings[0], strings[1], strings[2], mavenUrl, jarPath, "20000"); } else {/*from ww w.j a va 2s . c o m*/ boolean isCaching = ConfigurationManagerHelper.getConfigurationManagerHelper().getConfigurationManager() .getBoolean("artifact.caching", true); String cachePath = ConfigurationManagerHelper.getConfigurationManagerHelper().getConfigurationManager() .get("artifact.cache.path", "/temp/cache"); String cachedFilename = cachePath + filename; String artifactPath = null; // ?? ? ?? ? ?? . if (isCaching) { artifactPath = cachedFilename; } else { artifactPath = jarPath + "/" + temporaryPath; } FileSystemUtils.testCreateDir(new Path(FileSystemUtils.correctPath(FileUtils.getPath(artifactPath)))); try { InputStream is = HdfsUtils.getInputStream(fs, filename); File outputFile = new File(artifactPath); FileOutputStream fos = new FileOutputStream(outputFile); org.springframework.util.FileCopyUtils.copy(is, fos); logger.info("Artifact [{}]? [{}] ? .", filename, artifactPath); return artifactPath; } catch (IOException e) { throw new WorkflowException(ExceptionUtils.getMessage( " Artifact '{}' ? .", artifactPath), e); } } }
From source file:org.shept.org.springframework.web.bind.support.FilterBindingInitializer.java
private void registerDependendEntities(ComponentDataBinder binder, Class clazz, String path) { Object ann = AnnotationUtils.findAnnotation(clazz, Entity.class); if (ann == null) return;//ww w . j a va2s . c o m for (Field field : clazz.getDeclaredFields()) { String propPath = path + PropertyAccessor.NESTED_PROPERTY_SEPARATOR + field.getName(); if (field.getType().equals(String.class)) { binder.registerCustomEditor(String.class, propPath, new StringTrimmerEditor(true)); if (logger.isInfoEnabled()) { logger.info("Registered nullable StringEditor for " + propPath); } } else { // here we need to prevent infinte recursions for example if a user contains a user contains a user ... Integer depth = StringUtils.countOccurrencesOf(path, PropertyAccessor.NESTED_PROPERTY_SEPARATOR); if (depth <= maxDepth) { registerDependendEntities(binder, field.getType(), propPath); } } } }
From source file:org.springframework.batch.core.jsr.configuration.xml.JsrBeanDefinitionDocumentReaderTests.java
@Test public void testSpringArtifactUniqueness() throws Exception { JobExecution jobExecution = runJob("jsrSpringInstanceTests", new Properties(), 10000L); String exitStatus = jobExecution.getExitStatus(); assertTrue("Exit status must contain listener1", exitStatus.contains("listener1")); assertTrue("exitStatus must contain 2 listener1 values", StringUtils.countOccurrencesOf(exitStatus, "listener1") == 2); exitStatus = exitStatus.replace("listener1", ""); assertTrue("Exit status must contain listener4", exitStatus.contains("listener4")); assertTrue("exitStatus must contain 2 listener4 values", StringUtils.countOccurrencesOf(exitStatus, "listener4") == 2); exitStatus = exitStatus.replace("listener4", ""); assertTrue("exitStatus must be empty", "".equals(exitStatus)); }