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

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

Introduction

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

Prototype

public static int lastIndexOf(final CharSequence seq, final CharSequence searchSeq) 

Source Link

Document

Finds the last index within a CharSequence, handling null .

Usage

From source file:org.kuali.coeus.common.impl.compliance.core.SpecialReviewServiceImpl.java

@Override
public int getProtocolIndex(String prefix) {
    int index = -1;

    int lastLeftBracketIndex = StringUtils.lastIndexOf(prefix, '[');
    int lastRightBracketIndex = StringUtils.lastIndexOf(prefix, ']');
    if (lastLeftBracketIndex != -1 && lastRightBracketIndex != -1) {
        String lineNumber = prefix.substring(lastLeftBracketIndex + 1, lastRightBracketIndex);
        if (NumberUtils.isDigits(lineNumber)) {
            index = Integer.parseInt(lineNumber);
        }/*ww w. ja  va 2  s. c  om*/
    }

    return index;
}

From source file:org.massyframework.assembly.base.web.HttpResourceProcessorManagement.java

protected String parseExtensionName(String path) {
    int index = StringUtils.lastIndexOf(path, AbstractHttpService.PATH_SEPARATOR);
    int index_ext = StringUtils.lastIndexOf(path, EXTENSION_SEPARATOR);
    if (index_ext > index) {
        return StringUtils.substring(path, index_ext);
    }//from ww w .  j a  va  2  s  .  com
    return null;
}

From source file:org.massyframework.modules.utils.SunJdkModuleExporter.java

/**
 * ?SunJdk??/*w  w w.j a  v a  2 s  . c o m*/
 * 
 * @param fileName
 * @return
 * @throws IOException
 */
protected List<String> getSunJdkPackageNames(String rtJar) throws IOException {
    Set<String> packageNames = new HashSet<String>();
    JarFile file = null;
    try {
        file = new JarFile(rtJar);
        Enumeration<JarEntry> em = file.entries();
        while (em.hasMoreElements()) {
            JarEntry entry = em.nextElement();
            if (!entry.isDirectory()) {
                String name = entry.getName();
                if (name.endsWith(".class")) {
                    int index = StringUtils.lastIndexOf(name, "/");
                    packageNames.add(StringUtils.substring(name, 0, index));
                }
            }
        }
    } finally {
        IOUtils.closeStream(file);
    }
    List<String> result = new ArrayList<String>(packageNames);
    Collections.sort(result);
    return result;
}

From source file:org.opens.tanaguru.ruleimplementation.link.AbstractDownloadableLinkRuleImplementation.java

/**
 * /*w  w w  . j  a  v a  2s. c  o m*/
 * @param uri
 * @return whether the current link has a proper extension (link.html)
 * @throws URIException
 */
private boolean isLinkWithProperExtension(URI uri) throws URIException {
    if (uri.hasQuery()) {
        return false;
    }
    String path = uri.getPath();
    if (StringUtils.isBlank(path) || StringUtils.equals(path, SLASH_CHAR)) {
        return false;
    }
    int lastSlash = StringUtils.lastIndexOf(path, SLASH_CHAR);
    if (StringUtils.substring(path, lastSlash).contains(POINT_CHAR)) {
        return true;
    }

    return false;
}

From source file:org.yamj.core.service.artwork.ArtworkTools.java

/**
 * Get a part of the URL as hash code.//  w  w w . jav  a 2s .com
 * 
 * @param url
 * @return the hash code
 */
private static String getPartialHashCode(String url) {
    String hashCode = null;
    try {
        int index = StringUtils.lastIndexOf(url, "/");
        if (index > -1) {
            String tmp = url.substring(index + 1);
            index = tmp.indexOf(".");
            if (index > -1) {
                hashCode = tmp.substring(0, index);
            }
        }
    } catch (Exception ignore) {
        // ignore any exception
    }
    return hashCode;
}

From source file:Singletons.HeuristicsLoader.java

@PostConstruct
public void load() {
    Categories.populate();/*from  w w  w  . ja va2s . c om*/

    Set<File> setPathResources = new TreeSet();
    //        setPathResources.addAll(FacesContext.getCurrentInstance().getExternalContext().getResourcePaths("/resources/private/"));
    //        File file = new File ("/usr/sharedfilesapps/lexicons");
    File file;
    if (Parameters.local) {
        file = new File(
                "H:\\Docs Pro Clement\\NetBeansProjects\\Umigon_mavenized\\src\\main\\webapp\\resources\\private\\");
    } else {
        file = new File("/usr/sharedfilesapps/lexicons");
    }
    File[] files = file.listFiles();
    setPathResources.addAll(Arrays.asList(files));
    //        System.out.println("folder is: " + folder.getCanonicalPath());
    mapHeuristics = new HashMap();
    setNegations = new HashSet();
    setTimeTokens = new HashSet();
    setFalsePositiveOpinions = new HashSet();
    setIronicallyPositive = new HashSet();
    setModerators = new HashSet();
    mapH1 = new HashMap();
    mapH2 = new HashMap();
    mapH4 = new HashMap();
    mapH3 = new HashMap();
    mapH5 = new HashMap();
    mapH6 = new HashMap();
    mapH7 = new HashMap();
    mapH8 = new HashMap();
    mapH9 = new HashMap();
    mapH10 = new HashMap();
    mapH11 = new HashMap();
    mapH12 = new HashMap();
    mapH13 = new HashMap();

    //        for (File file : arrayFiles) {
    for (File filezz : setPathResources) {
        try {
            InputStream inp = new FileInputStream(filezz.getPath());
            br = new BufferedReader(new InputStreamReader(inp));
            if (!filezz.getPath().contains("_")) {
                continue;
            }
            String fileName;
            if (Parameters.local) {
                fileName = StringUtils.substring(filezz.getPath(),
                        StringUtils.lastIndexOf(filezz.getPath(), "\\") + 1);
            } else {
                fileName = StringUtils.substring(filezz.getPath(),
                        StringUtils.lastIndexOf(filezz.getPath(), "/") + 1);
            }

            int map = Integer.parseInt(StringUtils.left(fileName, fileName.indexOf("_")));
            if (map == 0) {
                continue;
            }
            //            System.out.println("map: " + map);
            //            System.out.println("loading " + pathFile);
            //            System.out.println("folder is: " + folder.getCanonicalPath());

            String term = null;
            String featureString;
            String feature;
            String rule = null;
            String fields[];
            String[] parametersArray;
            String[] featuresArray;
            Set<String> featuresSet;
            Iterator<String> featuresSetIterator;
            String field0;
            String field1;
            String field2;
            //mapFeatures:
            //key: a feature
            //value: a set of parameters for the given feature
            Multimap<String, Set<String>> mapFeatures;
            while ((string = br.readLine()) != null) {
                fields = string.split("\t", -1);
                mapFeatures = HashMultimap.create();

                //sometimes the heuristics is just a term, not followed by a feature or a rule
                //in this case put a null value to these fields
                field0 = fields[0].trim();
                if (field0.isEmpty()) {
                    continue;
                }
                field1 = (fields.length < 2) ? null : fields[1].trim();
                field2 = (fields.length < 3) ? null : fields[2].trim();

                term = field0;
                featureString = field1;
                rule = field2;

                //parse the "feature" field to disentangle the feature from the parameters
                //this parsing rule will be extended to allow for multiple features
                //                if (featureString.contains("+++")) {
                //                    System.out.println("featureString containing +++ " + featureString);
                //                }
                featuresArray = featureString.split("\\+\\+\\+");
                featuresSet = new HashSet(Arrays.asList(featuresArray));
                featuresSetIterator = featuresSet.iterator();
                while (featuresSetIterator.hasNext()) {
                    featureString = featuresSetIterator.next();
                    //                    System.out.println("featureString: " + featureString);
                    //                    if (featureString.contains("///")) {
                    //                        System.out.println("featureString containing ||| " + featureString);
                    //                    }
                    if (featureString.contains("///")) {
                        parametersArray = StringUtils.substringAfter(featureString, "///").split("\\|");
                        feature = StringUtils.substringBefore(featureString, "///");
                        mapFeatures.put(feature, new HashSet(Arrays.asList(parametersArray)));
                    } else {
                        mapFeatures.put(featureString, null);
                    }
                }

                //                if (term.equals("I was wondering")){
                //                    System.out.println("HERE!!!!");
                //                }
                //                System.out.println("feature: "+feature);
                heuristic = new Heuristic();
                heuristic.generateNewHeuristic(term, mapFeatures, rule);
                mapHeuristics.put(term, heuristic);
                //positive
                if (map == 1) {
                    mapH1.put(term, heuristic);
                    continue;
                }
                //negative
                if (map == 2) {
                    mapH2.put(term, heuristic);
                    continue;
                }
                //strong
                if (map == 3) {
                    mapH3.put(term, heuristic);
                    continue;
                }
                //time
                if (map == 4) {
                    mapH4.put(term, heuristic);
                    continue;
                }
                //question
                if (map == 5) {
                    mapH5.put(term, heuristic);
                    continue;
                }
                //subjective
                if (map == 6) {
                    mapH6.put(term, heuristic);
                    continue;
                }
                //address
                if (map == 7) {
                    mapH7.put(term, heuristic);
                    continue;
                }
                //humor
                if (map == 8) {
                    mapH8.put(term, heuristic);
                    continue;
                }
                //commercial offer
                if (map == 9) {
                    mapH9.put(term, heuristic);
                    continue;
                }
                //negations
                if (map == 10) {
                    setNegations.add(term);
                    continue;
                }
                //hints difficulty
                if (map == 11) {
                    mapH11.put(term, heuristic);
                    continue;
                }
                //time indications
                if (map == 12) {
                    setTimeTokens.add(term);
                    continue;
                }
                //time indications
                if (map == 13) {
                    mapH13.put(term, heuristic);
                    continue;
                }
                //set of terms which look like opinions but are false postives
                if (map == 12) {
                    setFalsePositiveOpinions.add(term);
                    continue;
                }
                //set of terms which look like opinions but are false postives
                if (map == 15) {
                    setIronicallyPositive.add(term);
                    continue;
                }

                //set of moderators
                if (map == 16) {
                    setModerators.add(term);
                    continue;
                }

            }
            br.close();
        } //        System.out.println(
          //                "total number heuristics used: " + mapHeuristics.keySet().size());
          //        System.out.println(
          //                "--------------------------------------------");
          //
          //        System.out.println(
          //                "positive tone: " + mapH1.keySet().size());
          //        System.out.println(
          //                "negative tone: " + mapH2.keySet().size());
          //        System.out.println(
          //                "strength of opinion: " + mapH3.keySet().size());
          //        System.out.println(
          //                "time related: " + mapH4.keySet().size());
          //        System.out.println(
          //                "question: " + mapH5.keySet().size());
          //        System.out.println(
          //                "self turned: " + mapH6.keySet().size());
          //        System.out.println(
          //                "humor or light: " + mapH8.keySet().size());
          //        System.out.println(
          //                "direct address: " + mapH7.keySet().size());
          //        System.out.println(
          //                "commercial offer: " + mapH9.keySet().size());
        catch (IOException ex) {
            Logger.getLogger(HeuristicsLoader.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:topology.ActorTopology.java

/**
 * Returns the name of the Actor specified by <b>actorPath</b>. <br>
 * Example: <br>//from  w  w w  .j a v  a2  s .c o  m
 * getActorName("/user/ActorSupervisor/Some/Actor/Stuff") -> "Stuff"
 *
 * @param actorPath ActorPath (/user/ActorSupervisor/Some/Actor)
 * @return ActorName
 */
protected String getActorName(String actorPath) {
    int indexOfLastSlash = StringUtils.lastIndexOf(actorPath, "/");
    return actorPath.substring(indexOfLastSlash + 1);
}