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

The following examples show how to use org.apache.commons.lang.StringUtils#ordinalIndexOf() . 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 File: VariableCPInstruction.java    From systemds with 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 File: VariableCPInstruction.java    From systemds with 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 File: RangerHiveAuthorizer.java    From ranger with 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
Source File: DefaultWindowsSdkLocator.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static String formatVersion(String version) {
    int index = StringUtils.ordinalIndexOf(version, ".", 2);

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

    return version;
}
 
Example 5
Source File: DefaultWindowsSdkLocator.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static String formatVersion(String version) {
    int index = StringUtils.ordinalIndexOf(version, ".", 2);

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

    return version;
}
 
Example 6
Source File: DefaultWindowsSdkLocator.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static String formatVersion(String version) {
    int index = StringUtils.ordinalIndexOf(version, ".", 2);

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

    return version;
}
 
Example 7
Source File: DefaultWindowsSdkLocator.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 File: S3ParamsExtractor.java    From geowave with 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 File: AggregateTypes.java    From DDF with 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;
    }