Example usage for org.apache.commons.lang3 StringUtils ordinalIndexOf

List of usage examples for org.apache.commons.lang3 StringUtils ordinalIndexOf

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils ordinalIndexOf.

Prototype

public static int ordinalIndexOf(final CharSequence str, final CharSequence searchStr, final int ordinal) 

Source Link

Document

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

Usage

From source file:org.schedoscope.metascope.tasks.SchedoscopeSyncTask.java

private String getParameterValues(String urlPath, List<FieldEntity> parameters) {
    int index = StringUtils.ordinalIndexOf(urlPath, "/", 2) + 1;
    String[] parameterValues = urlPath.substring(index).split("/");
    String result = "";
    if (parameters != null) {
        for (int i = 0; i < parameters.size(); i++) {
            FieldEntity parameter = parameters.get(i);
            if (!result.isEmpty()) {
                result += "/";
            }/*from ww w  .ja  v a  2  s  .  c  om*/
            result += parameter.getName() + "=" + parameterValues[i];
        }
    }
    return result;
}

From source file:org.schedoscope.metascope.tasks.SchedoscopeSyncTask.java

private Map<String, String> getParameterAsMap(String urlPath, List<FieldEntity> parameters) {
    int index = StringUtils.ordinalIndexOf(urlPath, "/", 2) + 1;
    String[] parameterValues = urlPath.substring(index).split("/");
    Map<String, String> map = new HashMap<String, String>();
    if (parameters != null) {
        for (int i = 0; i < parameters.size(); i++) {
            FieldEntity parameter = parameters.get(i);
            map.put(parameter.getName(), parameterValues[i]);
        }/*from w w w.j  av  a 2s  .  c  o  m*/
    }
    return map;
}

From source file:org.schedoscope.metascope.tasks.SchedoscopeSyncTask.java

private String viewIdFromUrlPath(String dependencyUrlPath) {
    int index = StringUtils.ordinalIndexOf(dependencyUrlPath, "/", 2) + 1;
    String[] parameterValues = dependencyUrlPath.substring(index).split("/");
    String result = "";

    if (parameterValues.length == 1 && parameterValues[0].isEmpty()) {
        return "root";
    }//from ww w  . jav a2s .co  m

    for (int i = 0; i < parameterValues.length; i++) {
        result += parameterValues[i];
    }
    return result;
}

From source file:sonicScream.models.Script.java

/**
 * Returns the Script's tree with everything removed but each entry's title
 * and its wave file list, and flattens the hierarchy.
 * Initializes the rootNode if it has not yet been initialized.
 * @param forceUpdate If true, will force the method to regenerate the simple tree from the current rootNode tree.
 * @return A simplified version of the Script's tree.
 */// w  w w . j a v  a2  s  . co  m
public TreeItem<String> getSimpleTree(boolean forceUpdate) {
    if (_simpleRootNode != null && !forceUpdate) {
        return _simpleRootNode;
    }
    if (_rootNode == null) {
        _rootNode = getRootNode();
    }
    TreeItem<String> local = new TreeItem<String>("root");
    for (TreeItem<String> child : getRootNode().getChildren()) {
        List<TreeItem<String>> localWaveStrings = FXCollections.observableArrayList();
        List<TreeItem<String>> waveStrings = getWaveStrings(child).orElse(null);
        if (waveStrings == null)
            continue;
        for (TreeItem<String> wave : waveStrings) {
            TreeItem<String> sound = new TreeItem<String>();
            //Remove whitespace, quotes, and value# text.
            String waveValue = wave.getValue().trim();
            int thirdQuoteIndex = StringUtils.ordinalIndexOf(waveValue, "\"", 3);
            waveValue = (waveValue.substring(thirdQuoteIndex + 1, waveValue.length() - 1));
            sound.setValue(waveValue);
            localWaveStrings.add(sound);
        }
        TreeItem<String> localChild = new TreeItem<>(child.getValue());
        localChild.getChildren().setAll(localWaveStrings);
        local.getChildren().add(localChild);
    }
    _simpleRootNode = local;
    return _simpleRootNode;
}

From source file:sonicScream.utilities.StringParsing.java

public static String rootSoundToSimpleSound(String rootSound) {
    rootSound = rootSound.trim();//from  www.j  a  v  a  2  s .  c o  m
    int thirdQuoteIndex = StringUtils.ordinalIndexOf(rootSound, "\"", 3);
    rootSound = (rootSound.substring(thirdQuoteIndex + 1, rootSound.length() - 1));
    return rootSound;
}

From source file:VCF.Genotype.java

/**
 * Get a specified piece of data for this genotype.  Returns "." if field is
 * not present for this genotype.//from   ww w.j a  v  a  2 s.com
 * @param name The format of the data to be retrieved (as a string)
 * @return The data
 * @throws VCF.Exceptions.VCFNoDataException If there is a no data for the
 * requested format
 */
public String getData(String name) throws VCFNoDataException {
    List<String> format = position.getFormat();
    int pos = format.indexOf(name);

    String info = geno.getInfo();
    if (pos == -1) {
        throw new VCFNoDataException("No data field called " + name);
    }

    if (StringUtils.countMatches(info, ':') < pos) {
        return ".";
    } else {
        int start;
        if (pos == 0) {
            start = 0;
        } else {
            start = StringUtils.ordinalIndexOf(info, ":", pos) + 1;
        }
        int end = StringUtils.ordinalIndexOf(info, ":", pos + 1);
        if (end == -1) {
            end = info.length();
        }

        return info.substring(start, end);

        //            Pattern p = Pattern.compile("(?:\\S+?:){" + pos + "}(\\S+?)(?::|$)");
        //            Matcher m = p.matcher(geno.getInfo());
        //            m.find();
        //            return m.group(1);
    }
}

From source file:VCF.Genotype.java

/**
 * Change a particular piece of data associated with the genotype
 * @param name The format of the data to be changed (as a string)
 * @param value The new value/*  w  w  w  .  j  av  a2 s. c o m*/
 * @throws VCF.Exceptions.VCFNoDataException If there is a no data for the
 * requested format
 */
public void replaceData(String name, String value) throws VCFNoDataException {
    List<String> format = position.getFormat();
    int pos = format.indexOf(name);
    if (pos == -1) {
        throw new VCFNoDataException("No data field called " + name);
    }

    String info = geno.getInfo();
    int start = 0;
    if (pos > 0) {
        start = StringUtils.ordinalIndexOf(info, ":", pos) + 1;
    }
    int end = info.length();
    if (pos < format.size() - 1) {
        end = StringUtils.ordinalIndexOf(info, ":", pos + 1);
    }
    geno.setInfo(StringUtils.overlay(info, value, start, end));
}

From source file:VCF.Genotype.java

/**
 * Remove data for the given format.  It is up to the caller to ensure the
 * appropriate format is removed from the position.
 * @param name The name of the format data to remove
 * @throws VCFNoDataException If there is no data field with that name
 *///from   w ww .  java 2  s  .c o  m
public void removeData(String name) throws VCFNoDataException {
    List<String> format = position.getFormat();
    int pos = format.indexOf(name);
    if (pos == -1) {
        throw new VCFNoDataException("No data field called " + name);
    }

    String info = geno.getInfo();
    int start = 0;
    if (pos > 0) {
        start = StringUtils.ordinalIndexOf(info, ":", pos);
    }
    int end = info.length();
    if (pos < format.size() - 1) {
        end = StringUtils.ordinalIndexOf(info, ":", pos + 1);
    }
    geno.setInfo(StringUtils.overlay(info, "", start, end));
}

From source file:wherehows.util.UrnUtil.java

/**
 * Parse WH dataset urn into platform, prefix, parent name, dataset name
 * For platform:///abc ->  prefix '', parent '', dataset 'abc'
 * For hdfs:///a/b/c/d  ->  prefix '/a/b', parent '/a/b/c', dataset 'd'
 * For platform:///a/b  ->  prefix '/a', parent 'a', dataset 'b'
 * @param urn String//from   ww w  .jav a  2 s.  c om
 * @return String[platform, prefix, parentName, datasetName]
 */
public static String[] parseWhDatasetUrn(@Nonnull String urn) {
    String platform = urn.split(":///")[0];
    String fullname = urn.split(":///")[1];

    String prefix;
    String parent;
    String datasetName;
    if (fullname.indexOf('/') < 0) {
        prefix = "";
        parent = "";
        datasetName = fullname;
    } else if ("hdfs".equalsIgnoreCase(platform)) {
        parent = "/" + fullname.substring(0, fullname.lastIndexOf('/'));
        prefix = "/" + fullname.substring(0, StringUtils.ordinalIndexOf(fullname, "/", 2));
        datasetName = fullname.substring(fullname.lastIndexOf('/') + 1);
    } else {
        parent = fullname.substring(0, fullname.lastIndexOf('/'));
        prefix = "/" + parent;
        datasetName = fullname.substring(fullname.lastIndexOf('/') + 1);
    }

    return new String[] { platform, prefix, parent, datasetName };
}