当前位置: 首页>>代码示例>>Java>>正文


Java StringUtils.countOccurrencesOf方法代码示例

本文整理汇总了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");
	}
}
 
开发者ID:tairmansd,项目名称:CriteriaBuilder,代码行数:58,代码来源:CriteriaServiceImpl.java

示例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;
}
 
开发者ID:forweaver,项目名称:forweaver2.0,代码行数:38,代码来源:GitUtil.java

示例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);
}
 
开发者ID:forweaver,项目名称:forweaver2.0,代码行数:7,代码来源:Weaver.java

示例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");
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:76,代码来源:ConfigUtils.java

示例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));

			}
		}
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:73,代码来源:OsgiBundleResourcePatternResolver.java

示例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));
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:55,代码来源:ServletContextResourcePatternResolver.java

示例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, ":");
}
 
开发者ID:Vyserion,项目名称:lodbot,代码行数:10,代码来源:TestUtils.java


注:本文中的org.springframework.util.StringUtils.countOccurrencesOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。