Example usage for org.apache.commons.lang StringUtils lastOrdinalIndexOf

List of usage examples for org.apache.commons.lang StringUtils lastOrdinalIndexOf

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils lastOrdinalIndexOf.

Prototype

public static int lastOrdinalIndexOf(String str, String searchStr, int ordinal) 

Source Link

Document

Finds the n-th last index within a String, handling null.

Usage

From source file:de.tsystems.mms.apm.performancesignature.viewer.ViewerWaitForJob.java

@Override
public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnull Launcher launcher,
        @Nonnull TaskListener listener) throws InterruptedException, IOException {
    PrintStream logger = listener.getLogger();
    JenkinsServerConnection serverConnection = ViewerUtils.createJenkinsServerConnection(jenkinsJob);

    JobWithDetails job = serverConnection.getJenkinsJob().details();
    ViewerEnvInvisAction envInvisAction = run.getAction(ViewerEnvInvisAction.class);
    BuildWithDetails build;//from   ww  w .jav  a 2 s.c  om
    if (envInvisAction != null) {
        build = job.getBuildByNumber(envInvisAction.getCurrentBuild()).details();
    } else {
        build = job.getLastBuild().details();
    }

    logger.println(Messages.ViewerWaitForJob_WaitingForJob(job.getName(), String.valueOf(build.getNumber())));
    boolean buildFinished = build.isBuilding();
    while (buildFinished) {
        Thread.sleep(waitForPollingInterval);
        buildFinished = build.details().isBuilding();
    }

    logger.println(Messages.ViewerWaitForJob_JenkinsJobFinished());
    BuildResult buildResult = build.details().getResult();

    logger.println(Messages.ViewerWaitForJob_JenkinsJobStatus(buildResult));
    if (!buildResult.equals(BuildResult.SUCCESS) && !buildResult.equals(BuildResult.UNSTABLE)) {
        String output = build.getConsoleOutputText();
        logger.println(output.substring(StringUtils.lastOrdinalIndexOf(output, "\n", 5) + 1)); //get the last 5 lines of console output
        throw new AbortException(Messages.ViewerWaitForJob_JenkinsJobFailed());
    }
}

From source file:com.oneops.antenna.domain.transform.impl.HPOMTransformer.java

public String getComponentName(String ciName) {

    int index = StringUtils.lastOrdinalIndexOf(ciName, "-", 2);
    if (!(index > 0)) {
        return null;
    }//w ww.j ava2 s  .  co  m
    return ciName.substring(0, index);
}

From source file:org.apache.hadoop.hive.ql.udf.generic.GenericUDFSubstringIndex.java

@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
    // str//from  w  w w. ja  v a 2s  .co m
    String str = getStringValue(arguments, 0, converters);
    if (str == null) {
        return null;
    }
    if (str.length() == 0) {
        output.set("");
        return output;
    }

    // delim
    String delim;
    if (isDelimConst) {
        delim = delimConst;
    } else {
        delim = getStringValue(arguments, 1, converters);
    }
    if (delim == null) {
        return null;
    }
    if (delim.length() == 0) {
        output.set("");
        return output;
    }

    // count
    Integer countV;
    if (isCountConst) {
        countV = countConst;
    } else {
        countV = getIntValue(arguments, 2, converters);
    }
    if (countV == null) {
        return null;
    }
    int count = countV.intValue();
    if (count == 0) {
        output.set("");
        return output;
    }

    // get substring
    String res;
    if (count > 0) {
        int idx = StringUtils.ordinalIndexOf(str, delim, count);
        if (idx != -1) {
            res = str.substring(0, idx);
        } else {
            res = str;
        }
    } else {
        int idx = StringUtils.lastOrdinalIndexOf(str, delim, -count);
        if (idx != -1) {
            res = str.substring(idx + 1);
        } else {
            res = str;
        }
    }

    output.set(res);
    return output;
}

From source file:org.onosproject.influxdbmetrics.DefaultInfluxDbMetricsRetriever.java

/**
 * Returns metric name from full name./*from   w w  w.  j ava2  s . c  o m*/
 * The elements in full name is split by using '.';
 * We assume that the metric name always comes after the last three '.'
 *
 * @param fullName full name
 * @return metric name
 */
private String getMetricName(String fullName) {
    int index = StringUtils.lastOrdinalIndexOf(fullName, METRIC_DELIMITER, NUB_OF_DELIMITER);
    if (index != -1) {
        return StringUtils.substring(fullName, index + 1);
    } else {
        log.warn("Database {} contains malformed metric name.", database);
        return null;
    }
}

From source file:org.onosproject.influxdbmetrics.DefaultInfluxDbMetricsRetriever.java

/**
 * Returns node id from full name.//from   ww  w .j av  a2s  .c om
 * The elements in full name is split by using '.';
 * We assume that the node id always comes before the last three '.'
 *
 * @param fullName full name
 * @return node id
 */
private String getNodeId(String fullName) {
    int index = StringUtils.lastOrdinalIndexOf(fullName, METRIC_DELIMITER, NUB_OF_DELIMITER);
    if (index != -1) {
        return StringUtils.substring(fullName, 0, index);
    } else {
        log.warn("Database {} contains malformed node id.", database);
        return null;
    }
}