本文整理匯總了Java中org.springframework.util.StringUtils.countOccurrencesOf方法的典型用法代碼示例。如果您正苦於以下問題:Java StringUtils.countOccurrencesOf方法的具體用法?Java StringUtils.countOccurrencesOf怎麽用?Java StringUtils.countOccurrencesOf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.util.StringUtils
的用法示例。
在下文中一共展示了StringUtils.countOccurrencesOf方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: populatePredicates
import org.springframework.util.StringUtils; //導入方法依賴的package包/類
/**
* input query = field:abcAND(field<bcdOR(field:defANDfield>=efg))
* return field:abc,field<bcd,field:def,field>=efg,AND,OR,AND
* @param root
* @param query
* @param predicates
* @return
* @return
*/
private Predicate populatePredicates(Root<T> root, String query)
{
if(StringUtils.countOccurrencesOf(query, Conjunctions.SP.toString()) == StringUtils.countOccurrencesOf(query, Conjunctions.EP.toString())) {
LinkedList<String> postfix = createPostfixExpression(query);
boolean hasSingleSearchField = postfix.size() == 1;
Map<String, Predicate> predicateMap = new LinkedHashMap<>();
for (int i = 0; i < postfix.size(); i++)
{
String attr = postfix.get(i);
if(Conjunctions.isConjunction(attr)) {
String rightOperand = postfix.get(i-1);
String leftOperand = postfix.get(i-2);
String key = rightOperand + attr + leftOperand;
Predicate rightPredicate = (predicateMap.containsKey(rightOperand))? predicateMap.get(rightOperand) : buildPredicate(root, new SearchField(rightOperand));
Predicate leftPredicate = (predicateMap.containsKey(leftOperand))? predicateMap.get(leftOperand) : buildPredicate(root, new SearchField(leftOperand));
postfix.set(i-2, key);
postfix.remove(i);
postfix.remove(i-1);
//reset loop
i=0;
List<Predicate> combinedPredicates = new ArrayList<>();
combinedPredicates.add(leftPredicate);
combinedPredicates.add(rightPredicate);
Predicate combinedPredicate = buildPredicateWithOperator(root, Conjunctions.getEnum(attr), combinedPredicates);
predicateMap.put(key, combinedPredicate);
}
}
if(hasSingleSearchField) {
SearchField field = new SearchField(postfix.get(0));
predicateMap.put(postfix.get(0), buildPredicate(root, field));
}
return (Predicate) predicateMap.values().toArray()[predicateMap.size()-1];
} else {
throw new RuntimeException("MALFORMED.QUERY");
}
}
示例2: getCommitStatistics
import org.springframework.util.StringUtils; //導入方法依賴的package包/類
/** 각 유저가 날짜별로 커밋을 한 정보를 취합함.
* @return
*/
public GitParentStatistics getCommitStatistics(){
GitParentStatistics gitParentStatistics = new GitParentStatistics();
try{
for(RevCommit rc:git.log().all().call()){
String diffs = new String();
ByteArrayOutputStream out = new ByteArrayOutputStream();
if(rc.getParentCount()>0){
DiffFormatter df = new DiffFormatter(out);
df.setRepository(this.localRepo);
df.format(rc.getParent(0), rc);
df.flush();
diffs = out.toString();
} else {
diffs = simpleFileBrowser(rc);
}
int addFile = StringUtils.countOccurrencesOf(diffs, "--- /dev/null");// 추가한 파일 수
int deleteFile = StringUtils.countOccurrencesOf(diffs, "+++ /dev/null");// 삭제한 파일 수
diffs = StringUtils.delete(diffs, "\n--- ");
diffs = StringUtils.delete(diffs, "\n+++ ");
gitParentStatistics.addGitChildStatistics(
new GitChildStatistics(
rc.getAuthorIdent().getEmailAddress(), // 유저 이메일
StringUtils.countOccurrencesOf(diffs, "\n+"), //추가한 라인 수
StringUtils.countOccurrencesOf(diffs, "\n-"), //삭제한 라인 수
addFile,
deleteFile,
rc.getAuthorIdent().getWhen())); // 날짜
}
}catch(Exception e){
System.err.println(e.getMessage());
}
return gitParentStatistics;
}
示例3: getInfo
import org.springframework.util.StringUtils; //導入方法依賴的package包/類
public String getInfo(String field,String search) {
Object value = weaverInfo.get(field);
if(value == null)
value = "0";
return ""+StringUtils.countOccurrencesOf(value.toString(),search);
}
示例4: matchExtenderVersionRange
import org.springframework.util.StringUtils; //導入方法依賴的package包/類
public static boolean matchExtenderVersionRange(Bundle bundle, String header, Version versionToMatch) {
Assert.notNull(bundle);
// get version range
String range = (String) 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");
}
示例5: doRetrieveMatchingBundleEntries
import org.springframework.util.StringUtils; //導入方法依賴的package包/類
/**
* Searches each level inside the bundle for entries based on the search strategy chosen.
*
* @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));
}
}
}
}
示例6: doRetrieveMatchingServletContextResources
import org.springframework.util.StringUtils; //導入方法依賴的package包/類
/**
* Recursively retrieve ServletContextResources that match the given pattern,
* adding them to the given result set.
* @param servletContext the ServletContext to work on
* @param fullPattern the pattern to match against,
* with preprended root directory path
* @param dir the current directory
* @param result the Set of matching Resources to add to
* @throws IOException if directory contents could not be retrieved
* @see ServletContextResource
* @see javax.servlet.ServletContext#getResourcePaths
*/
protected void doRetrieveMatchingServletContextResources(
ServletContext servletContext, String fullPattern, String dir, Set<Resource> result)
throws IOException {
Set<String> candidates = servletContext.getResourcePaths(dir);
if (candidates != null) {
boolean dirDepthNotFixed = fullPattern.contains("**");
int jarFileSep = fullPattern.indexOf(ResourceUtils.JAR_URL_SEPARATOR);
String jarFilePath = null;
String pathInJarFile = null;
if (jarFileSep > 0 && jarFileSep + ResourceUtils.JAR_URL_SEPARATOR.length() < fullPattern.length()) {
jarFilePath = fullPattern.substring(0, jarFileSep);
pathInJarFile = fullPattern.substring(jarFileSep + ResourceUtils.JAR_URL_SEPARATOR.length());
}
for (String currPath : candidates) {
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("/") && (dirDepthNotFixed || StringUtils.countOccurrencesOf(currPath, "/") <=
StringUtils.countOccurrencesOf(fullPattern, "/"))) {
// Search subdirectories recursively: ServletContext.getResourcePaths
// only returns entries for one directory level.
doRetrieveMatchingServletContextResources(servletContext, fullPattern, currPath, result);
}
if (jarFilePath != null && getPathMatcher().match(jarFilePath, currPath)) {
// Base pattern matches a jar file - search for matching entries within.
String absoluteJarPath = servletContext.getRealPath(currPath);
if (absoluteJarPath != null) {
doRetrieveMatchingJarEntries(absoluteJarPath, pathInJarFile, result);
}
}
if (getPathMatcher().match(fullPattern, currPath)) {
result.add(new ServletContextResource(servletContext, currPath));
}
}
}
}
示例7: getParameterCount
import org.springframework.util.StringUtils; //導入方法依賴的package包/類
/**
* Returns the parameter count for a given SQL query.
* @param sql The SQL query to examine.
* @return The number of parameters.
*/
public static int getParameterCount(String sql)
{
return StringUtils.countOccurrencesOf(sql, ":");
}