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

The following examples show how to use org.apache.commons.lang.StringUtils#ordinalIndexOf() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: systemds   File: VariableCPInstruction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void updateInstructionThreadID(String pattern, String replace) {
	if(    opcode == VariableOperationCode.CreateVariable
		|| opcode == VariableOperationCode.SetFileName )
	{
		//replace in-memory instruction
		getInput2().setName(getInput2().getName().replaceAll(pattern, replace));

		// Find a start position of file name string.
		int iPos = StringUtils.ordinalIndexOf(instString, Lop.OPERAND_DELIMITOR, CREATEVAR_FILE_NAME_VAR_POS);
		// Find a end position of file name string.
		int iPos2 = StringUtils.indexOf(instString, Lop.OPERAND_DELIMITOR, iPos+1);
		
		StringBuilder sb = new StringBuilder();
		sb.append(instString.substring(0,iPos+1));			// It takes first part before file name.
		// This will replace 'pattern' with 'replace' string from file name.
		sb.append(ProgramConverter.saveReplaceFilenameThreadID(instString.substring(iPos+1, iPos2+1), pattern, replace));
		sb.append(instString.substring(iPos2+1));			// It takes last part after file name.
		
		instString = sb.toString();
	}
}
 
Example 2
Source Project: systemds   File: VariableCPInstruction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void updateInstructionThreadID(String pattern, String replace) {
	if(    opcode == VariableOperationCode.CreateVariable
		|| opcode == VariableOperationCode.SetFileName )
	{
		//replace in-memory instruction
		getInput2().setName(getInput2().getName().replaceAll(pattern, replace));

		// Find a start position of file name string.
		int iPos = StringUtils.ordinalIndexOf(instString, Lop.OPERAND_DELIMITOR, CREATEVAR_FILE_NAME_VAR_POS);
		// Find a end position of file name string.
		int iPos2 = StringUtils.indexOf(instString, Lop.OPERAND_DELIMITOR, iPos+1);
		
		StringBuilder sb = new StringBuilder();
		sb.append(instString.substring(0,iPos+1));			// It takes first part before file name.
		// This will replace 'pattern' with 'replace' string from file name.
		sb.append(ProgramConverter.saveReplaceFilenameThreadID(instString.substring(iPos+1, iPos2+1), pattern, replace));
		sb.append(instString.substring(iPos2+1));			// It takes last part after file name.
		
		instString = sb.toString();
	}
}
 
Example 3
Source Project: ranger   File: RangerHiveAuthorizer.java    License: Apache License 2.0 6 votes vote down vote up
private String buildPathForException(String path, HiveOperationType hiveOpType) {
	String ret  	= path;
	int endIndex 	= 0;
	switch(hiveOpType) {
		case DESCTABLE:
			ret = path + "/*";
			break;
		case QUERY:
			try {
				endIndex = StringUtils.ordinalIndexOf(path, "/", 2);
				ret = path.substring(0,endIndex) + "/*";
			} catch( Exception e) {
				//omit and return the path.Log error only in debug.
				if(LOG.isDebugEnabled()) {
					LOG.debug("RangerHiveAuthorizer.buildPathForException(): Error while creating exception message ", e);
				}
			}
			break;
	}
	return ret;
}
 
Example 4
private static String formatVersion(String version) {
    int index = StringUtils.ordinalIndexOf(version, ".", 2);

    if (index != -1) {
        version = version.substring(0, index);
    }

    return version;
}
 
Example 5
private static String formatVersion(String version) {
    int index = StringUtils.ordinalIndexOf(version, ".", 2);

    if (index != -1) {
        version = version.substring(0, index);
    }

    return version;
}
 
Example 6
private static String formatVersion(String version) {
    int index = StringUtils.ordinalIndexOf(version, ".", 2);

    if (index != -1) {
        version = version.substring(0, index);
    }

    return version;
}
 
Example 7
private static String formatVersion(String version) {
    int index = StringUtils.ordinalIndexOf(version, ".", 2);

    if (index != -1) {
        version = version.substring(0, index);
    }

    return version;
}
 
Example 8
Source Project: geowave   File: S3ParamsExtractor.java    License: Apache License 2.0 5 votes vote down vote up
protected static S3Params extract(final URL url) throws IOException, IllegalArgumentException {

    if (!"s3".equals(url.getProtocol())) {
      throw new IllegalArgumentException("Unsupported protocol '" + url.getProtocol() + "'");
    }

    // bucket
    final int index = StringUtils.ordinalIndexOf(url.getPath(), "/", 2);
    final String bucket = url.getPath().substring(1, index);

    // key
    final String key = url.getPath().substring(index + 1);

    return new S3Params(bucket, key);
  }
 
Example 9
Source Project: DDF   File: AggregateTypes.java    License: Apache License 2.0 4 votes vote down vote up
public static AggregationResult newInstance(List<String> sqlResult, int numUnaggregatedFields) {

      AggregationResult result = new AggregationResult();

      for (String res : sqlResult) {

        int pos = StringUtils.ordinalIndexOf(res, "\t", numUnaggregatedFields);
        String groupByColNames = res.substring(0, pos);
        String[] stats = res.substring(pos + 1).split("\t");

        double[] statsDouble = new double[stats.length];

        for (int i = 0; i < stats.length; i++) {
          statsDouble[i] = "null".equalsIgnoreCase(stats[i]) ? Double.NaN : Utils.roundUp(Double.parseDouble(stats[i]));
        }

        result.put(groupByColNames, statsDouble);
      }

      return result;
    }