本文整理汇总了Java中org.apache.commons.lang3.StringUtils.countMatches方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.countMatches方法的具体用法?Java StringUtils.countMatches怎么用?Java StringUtils.countMatches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.StringUtils
的用法示例。
在下文中一共展示了StringUtils.countMatches方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCompleteQuery
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
* Get a complete ElasticSearch query
* @param parameters the match parameters that results must have
* @return the completed query
*/
private static String getCompleteQuery(String parameters){
StringBuilder builder = new StringBuilder();
boolean multiField = StringUtils.countMatches(parameters, "}},") > 0 && StringUtils.countMatches(parameters, "\n{\"match\": {\"") > 1;
// TODO: handle case when there is more than max results
builder.append("{\"size\": " + MAX_RESULTS + ",");
// find all
if (parameters.equals("")){
builder.append("\n\"query\": {\"match_all\": {}");
builder.append("}}\n}");
} else if (!multiField) {
builder.append("\n\"query\": {\"term\":{");
builder.append(parameters);
builder.append("}}\n}");
} else {
builder.append("\n\"query\":{\n\"bool\": {\n\"must\": [");
builder.append(parameters);
builder.append("]}}\n}");
}
return builder.toString();
}
示例2: isEntityValidForFilterUnsafe
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public static boolean isEntityValidForFilterUnsafe(String filter, Entity entity) throws IllegalArgumentException {
if (filter == null) return true;
if (StringUtils.countMatches(filter, "(") != StringUtils.countMatches(filter, ")"))
throw new IllegalArgumentException("Not an equal amount of opening and closing braces");
String[] splits = filter.split("[(),]");
for (int i = 0; i < splits.length; i++)
splits[i] = splits[i].trim();
if (!isEntityValidForName(splits[0], entity)) return false;
for (int i = 1; i < splits.length; i++) {
String[] modifier = splits[i].split("=");
if (modifier.length == 2) {
if (!isEntityValidForModifier(modifier[0].trim(), modifier[1].trim(), entity)) return false;
} else {
throw new IllegalArgumentException("No '=' sign in the modifier.");
}
}
return true;
}
示例3: getDrugClassDrugMutScores
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public Map<DrugClass, Map<Drug, Map<Mutation, Double>>> getDrugClassDrugMutScores() {
Map<DrugClass, Map<Drug, Map<Mutation, Double>>> result = new EnumMap<>(DrugClass.class);
for (DrugClass drugClass : gene.getDrugClasses()) {
result.put(drugClass, new EnumMap<>(Drug.class));
Map<Drug, Map<Mutation, Double>> drugClassResult = result.get(drugClass);
for (Drug drug : drugClass.getDrugsForHivdbTesting()) {
drugClassResult.put(drug, new LinkedHashMap<>());
Map<Mutation, Double> drugResult = drugClassResult.get(drug);
Map<String, Double> drugScores = separatedScores.getOrDefault(drug, Collections.emptyMap());
for (String key : drugScores.keySet()) {
if (StringUtils.countMatches(key, "+") > 1) {
continue;
}
Mutation mut = triggeredMuts.get(drug).get(key).first();
drugResult.put(mut, drugScores.get(key));
}
}
}
return result;
}
示例4: formatJavaSource
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public static String formatJavaSource(final String input) {
Iterable<String> split = Splitter.on("\n").trimResults().split(input);
int basicIndent = 4;
StringBuilder sb = new StringBuilder();
int indents = 0, empty = 0;
for (String line : split) {
indents -= StringUtils.countMatches(line, "}");
if (indents < 0) {
indents = 0;
}
if (!line.isEmpty()) {
sb.append(Strings.repeat(" ", basicIndent * indents));
sb.append(line);
sb.append("\n");
empty = 0;
} else {
empty++; // one empty line is allowed
if (empty < 2) {
sb.append("\n");
}
}
indents += StringUtils.countMatches(line, "{");
}
return ensureEndsWithSingleNewLine(sb.toString());
}
示例5: parseAddress
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public static InetSocketAddress parseAddress(String address) {
if(StringUtils.isBlank(address)) {
return null;
}
Matcher matcher = ipv6Pattern.matcher(address);
if(matcher.matches()) {
return parseMatch(matcher);
}
matcher = ipv4Pattern.matcher(address);
if(StringUtils.countMatches(address, ":") == 1 && matcher.matches()) {
return parseMatch(matcher);
}
logger.debug("Invalid address: {}. For ipv6 use de convention [address]:port. For ipv4 address:port", address);
return null;
}
示例6: toSimpleString
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
* 用于产生去掉空值属性并以换行符分割各属性键值的toString字符串
* @param obj
*/
public static String toSimpleString(Object obj) {
String toStringResult = ToStringBuilder.reflectionToString(obj, THE_STYLE);
String[] split = toStringResult.split(SimpleMultiLineToStringStyle.LINE_SEPARATOR);
StringBuilder result = new StringBuilder();
for (String string : split) {
if (string.endsWith(SimpleMultiLineToStringStyle.NULL_TEXT)) {
continue;
}
result.append(string + SimpleMultiLineToStringStyle.LINE_SEPARATOR);
}
if (result.length() == 0) {
return "";
}
//如果没有非空的属性,就输出 <all null properties>
if (StringUtils.countMatches(result, SimpleMultiLineToStringStyle.LINE_SEPARATOR) == 2) {
return result.toString().split(SimpleMultiLineToStringStyle.LINE_SEPARATOR)[0]
+ "<all null values>]";
}
return result.deleteCharAt(result.length() - 1).toString();
}
示例7: getArguments
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public List<String> getArguments() {
List<String> arguments = new ArrayList<>();
int elements = StringUtils.countMatches(logicRepresentation, ",");
if (elements == 0) {
arguments.add(getSubstring("(", ")"));
} else if (elements == 1) {
arguments.add(getSubstring("(", ","));
arguments.add(getSubstring(",", ")"));
} else if (elements > 1) {
arguments.add(getSubstring("(", ","));
String restString = getSubstring(",", ")");
String[] restArray = StringUtils.split(restString, ",");
for (String aRestArray : restArray) {
arguments.add(aRestArray);
}
}
return arguments;
}
示例8: toCustom
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public static String toCustom(String format, Duration time) {
long millis = time.toMillis();
long seconds = time.getSeconds();
long minutes = time.toMinutes();
long hours = time.toHours();
long days = time.toDays();
String ms = String.valueOf(millis - (seconds * 1000));
String s = String.valueOf(seconds - (minutes * 60));
String m = String.valueOf(minutes - (hours * 60));
String h = String.valueOf(hours - (days * 24));
String d = String.valueOf(days);
if (format.contains("s")) {
int msCount = StringUtils.countMatches(format, 's');
ms = ms.substring(0, msCount - 1);
}
return format.replace("%D", d).replace("%H", h).replace("%M", m).replace("%S", s).replaceAll("%+s*", ms);
}
示例9: findTagContent
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private void findTagContent() {
int startTags = StringUtils.countMatches(target, tag.getStartTag());
int endTags = StringUtils.countMatches(target, tag.getEndTag());
//make sure the amount of start and end tags are equal
if(startTags == endTags) {
String[] results = StringUtils.substringsBetween(target.toString(), tag.getStartTag().toString(), tag.getEndTag().toString());
for(String result : results) {
tagResult.addResult(result);
logger.log("Found Tag: %s", result);
}
} else {
//TODO: throw exception or something
logger.log("Tag counts don't match. Found %s start tags and %s end tags!", startTags, endTags);
}
}
示例10: resolveMacroNameAndContents
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
* Resolve macro name and contents from a create statement
* This works to involve quotations around a spaced macro name
* @param s The parameters of a create statement - The contents past the $macro create bit
* @return Two index array: [0] is the macro name, [1] is the contents
* Prerequisite: s.split() must have length of >= 2
*/
private static String[] resolveMacroNameAndContents(String s) {
String[] toReturn = new String[2];
if(s.contains("\"") && StringUtils.countMatches(s, "\"") > 1) {
int secondIndexOfQuotes = s.indexOf("\"", s.indexOf("\"") + 1);
toReturn[0] = s.substring(s.indexOf("\"") + 1, secondIndexOfQuotes);
toReturn[1] = s.substring(secondIndexOfQuotes + 2);
} else {
toReturn[0] = s.split(" ")[0];
toReturn[1] = Util.getCommandContents(s);
}
return toReturn;
}
示例11: getCurrentCursorLine
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
* Get current cursor line
*/
public int getCurrentCursorLine(Editable editable) {
int selectionStartPos = Selection.getSelectionStart(editable);
// no selection
if (selectionStartPos < 0) return -1;
String preSelectionStartText = editable.toString().substring(0, selectionStartPos);
return StringUtils.countMatches(preSelectionStartText, "\n");
}
示例12: fetchStructureDefinition
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@Override
public StructureDefinition fetchStructureDefinition(FhirContext theContext, String theUrl) {
String url = theUrl;
if (url.startsWith(URL_PREFIX_STRUCTURE_DEFINITION)) {
// no change
} else if (url.indexOf('/') == -1) {
url = URL_PREFIX_STRUCTURE_DEFINITION + url;
} else if (StringUtils.countMatches(url, '/') == 1) {
url = URL_PREFIX_STRUCTURE_DEFINITION_BASE + url;
}
return provideStructureDefinitionMap(theContext).get(url);
}
开发者ID:nhsconnect,项目名称:careconnect-reference-implementation,代码行数:13,代码来源:SNOMEDUKMockValidationSupport.java
示例13: extractParams
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
protected String extractParams(String str, Object... values) {
int args = values == null ? 0 : values.length;
if (args == 0) {
return str;
}
if (StringUtils.isBlank(str)) {
return str;
}
if (args != StringUtils.countMatches(str, ":")) {
throw new ParseSqlException("El número de parámetros no coincide en el predicado " + str);
}
ConditionValues cv = ConditionValuesParser.getInstance(str, values).parse();
str = cv.getCondition();
values = cv.getValues();
Matcher m = Pattern.compile(":([^\\s\\)]+)").matcher(str);
int i = 0;
while (m.find()) {
String paramName = m.group(1);
Object value = values[i++];
if (value instanceof StrQLBuilder) {
sqls.add(new Parameter<StrQLBuilder>(paramName, (StrQLBuilder) value));
continue;
}
if (value != null && value.getClass().isArray()) {
value = StrQLUtils.arrayToList(value); // convert array to list
}
params.add(new Parameter<Object>(paramName, value));
}
return str;
}
示例14: validatePageMinFile
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private static void validatePageMinFile(String string, String subString) {
if (StringUtils.countMatches(string, subString) != 1) {
throw new WMRuntimeException("Page resource update not supported");
}
}
示例15: executeUpdate
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
* Executes a SQL prepared statement for an update.
*
* @return the return code of the prepared statement
*
* @throws SQLException
* if a SQL Exception is raised
*/
public int executeUpdate() throws SQLException {
prepStatement = connection.prepareStatement(sql);
int numberOfIntMarks = StringUtils.countMatches(sql, "?");
int numberOfParams = params.size();
if (numberOfIntMarks != numberOfParams) {
throw new SQLException(
"sql statement numbers of \"?\" do no match number of parameters: "
+ numberOfIntMarks + " and " + numberOfParams);
}
for (int i = 0; i < params.size(); i++) {
int j = i + 1;
prepStatement.setObject(j, params.get(i));
}
int rc = -1;
String sqlLower = sql.toLowerCase();
if (sqlLower.startsWith(SELECT)) {
throw new SQLException("sql string is not an update: " + sql);
}
if (sqlLower.startsWith(UPDATE) || sqlLower.startsWith(DELETE)) {
if (sqlLower.indexOf(" " + WHERE + " ") == 0) {
throw new SQLException(
"update and delete are not permitted without a WHERE clause: "
+ sql);
}
}
if (sqlLower.startsWith(UPDATE) || sqlLower.startsWith(DELETE)
|| sqlLower.startsWith(INSERT)) {
rc = prepStatement.executeUpdate();
} else {
throw new SQLException(
"Statement is not INSERT / UPDATE / DELETE: " + sql);
}
debug(this.toString());
return rc;
}