Java Code Examples for org.apache.commons.lang.StringUtils.countMatches()

The following are Jave code examples for showing how to use countMatches() of the org.apache.commons.lang.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jfrog-idea-plugin   File: GradleScanManager.java   View Source Code Vote up 6 votes
private void populateDependenciesTree(ScanTreeNode scanTreeNode, DataNode<? extends AbstractDependencyData> dataNode) {
    String componentId = dataNode.getData().getExternalName();

    int colonCount = StringUtils.countMatches(componentId, ":");
    if (colonCount == 3) {
        // <Group ID>:<Artifact ID>:<Classifier>:<Version>. The classifier should be ignored.
        int secondColonIdx = componentId.indexOf(":", componentId.indexOf(":") + 1);
        int thirdColonIdx = componentId.indexOf(":", secondColonIdx + 1);
        componentId = componentId.substring(0, secondColonIdx) + componentId.substring(thirdColonIdx);
        colonCount--;
    }
    if (colonCount != 2) {
        if (StringUtils.isNotBlank(componentId)) {
            logger.warn("Bad component ID structure. Should be <GroupID>:<ArtifactID>:<Version>, got '" + componentId + "'");
        }
        return;
    }

    ComponentDetailImpl scanComponent = new ComponentDetailImpl(componentId, getArtifactChecksum(dataNode));
    ScanTreeNode treeNode = new ScanTreeNode(scanComponent);
    for (DataNode child : dataNode.getChildren()) {
        populateDependenciesTree(treeNode, child);
    }
    scanTreeNode.add(treeNode);
}
 
Example 2
Project: hadoop   File: INodeAttributeProvider.java   View Source Code Vote up 6 votes
@VisibleForTesting
String[] getPathElements(String path) {
  path = path.trim();
  if (path.charAt(0) != Path.SEPARATOR_CHAR) {
    throw new IllegalArgumentException("It must be an absolute path: " +
        path);
  }
  int numOfElements = StringUtils.countMatches(path, Path.SEPARATOR);
  if (path.length() > 1 && path.endsWith(Path.SEPARATOR)) {
    numOfElements--;
  }
  String[] pathElements = new String[numOfElements];
  int elementIdx = 0;
  int idx = 0;
  int found = path.indexOf(Path.SEPARATOR_CHAR, idx);
  while (found > -1) {
    if (found > idx) {
      pathElements[elementIdx++] = path.substring(idx, found);
    }
    idx = found + 1;
    found = path.indexOf(Path.SEPARATOR_CHAR, idx);
  }
  if (idx < path.length()) {
    pathElements[elementIdx] = path.substring(idx);
  }
  return pathElements;
}
 
Example 3
Project: JWT4B   File: TokenCheck.java   View Source Code Vote up 6 votes
public static boolean isValidJWT(String jwt) {
	if (StringUtils.countMatches(jwt, ".") != 2) {
		return false;
	}
	try {
		DecodedJWT decoded = JWT.decode(jwt);
		decoded.getAlgorithm();
		return true;
	} catch (Exception exception) {}
	return false;
}
 
Example 4
Project: Reer   File: StartScriptTemplateBindingFactory.java   View Source Code Vote up 5 votes
String createJoinedAppHomeRelativePath(String scriptRelPath) {
    int depth = StringUtils.countMatches(scriptRelPath, "/");
    if (depth == 0) {
        return "";
    }

    List<String> appHomeRelativePath = new ArrayList<String>(depth);
    for (int i = 0; i < depth; i++) {
        appHomeRelativePath.add("..");
    }

    return Joiner.on(windows ? "\\" : "/").join(appHomeRelativePath);
}
 
Example 5
Project: logistimo-web-service   File: BulkUploadMgr.java   View Source Code Vote up 5 votes
private static String getTrimmedErrorMessageString(String errMessage, int errorCount) {
  StringBuilder trimmedErrMsgSb = new StringBuilder();
  trimmedErrMsgSb.append(StringUtils.substringBeforeLast(
      errMessage.substring(0, ERROR_MESSAGE_MAX_LENGTH), BulkUploadMgr.MESSAGE_DELIMITER));
  int remainingErrorCount = errorCount - (StringUtils.countMatches(trimmedErrMsgSb.toString(), MESSAGE_DELIMITER) + 1);
  trimmedErrMsgSb.append(BulkUploadMgr.MESSAGE_DELIMITER).append(CharacterConstants.SPACE).append(ERRORS_TRUNCATED_MSG).append(CharacterConstants.O_BRACKET).append(ERROR_COUNT_MSG).append(remainingErrorCount).append(CharacterConstants.C_BRACKET);
  return trimmedErrMsgSb.toString();
}
 
Example 6
Project: jfrog-idea-plugin   File: GeneralInfo.java   View Source Code Vote up 5 votes
public String getArtifactId() {
    if (!isValid()) {
        return "";
    }
    int indexOfColon = componentId.indexOf(":");
    if (StringUtils.countMatches(componentId, ":") == 1) {
        return componentId.substring(0, indexOfColon);
    }
    return componentId.substring(indexOfColon + 1, componentId.lastIndexOf(":"));
}
 
Example 7
Project: jfrog-idea-plugin   File: GeneralInfo.java   View Source Code Vote up 5 votes
private boolean isValid() {
    int colonCount = StringUtils.countMatches(componentId, ":");
    if (colonCount != 1 && colonCount != 2) {
        log.warn("Bad component ID structure. Should be <GroupID>:<ArtifactID>:<Version> or <ArtifactID>:<Version>, got '" + componentId + "'");
        return false;
    }
    return true;
}
 
Example 8
Project: PRoST   File: Stats.java   View Source Code Vote up 5 votes
public boolean arePrefixesActive() {
  
  for(String propertyName : this.tableNames) {
    if(StringUtils.countMatches(propertyName, "_") > 2)
      return false;
  }
  
  return true;
}
 
Example 9
Project: JWT4B   File: PostBody.java   View Source Code Vote up 5 votes
public KeyValuePair getJWTFromPostBody() {
	int from = 0;
	int index = body.indexOf("&") == -1 ? body.length() : body.indexOf("&");
	int parameterCount = StringUtils.countMatches(body, "&") + 1;

	List<KeyValuePair> postParameterList = new ArrayList<KeyValuePair>();
	for (int i = 0; i < parameterCount; i++) {
		String parameter = body.substring(from, index);
		parameter = parameter.replace("&", "");

		String[] parameterSplit = parameter.split(Pattern.quote("="));
		if (parameterSplit.length > 1) {
			String name = parameterSplit[0];
			String value = parameterSplit[1];
			postParameterList.add(new KeyValuePair(name, value));
			from = index;
			index = body.indexOf("&", index + 1);
			if (index == -1) {
				index = body.length();
			}
		}
	}
	for (String keyword : tokenKeyWords) {
		for (KeyValuePair postParameter : postParameterList) {
			if (keyword.equals(postParameter.getName())
					&& TokenCheck.isValidJWT(postParameter.getValue())) {
				return postParameter;
			}
		}
	}
	return null;
}
 
Example 10
Project: satisfy   File: PDFWords.java   View Source Code Vote up 5 votes
private int getCountMatchesInCollectiont(String expectedValue, Collection<String> values) {
    int count = 0;
    for (String content : values) {
        count += StringUtils.countMatches(content, expectedValue);
    }
    return count;
}