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

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

Introduction

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

Prototype

public static boolean containsAny(CharSequence cs, CharSequence... searchCharSequences) 

Source Link

Document

Checks if the CharSequence contains any of the CharSequences in the given array.

A null CharSequence will return false .

Usage

From source file:rs.metropolitan.data_changer.DataFactory.java

public Object change(String data) {

    String trim = data.trim();//from  www  . ja v  a 2s .  c  om
    System.out.println(trim);
    String[] seps = { ",", "{", "}" };
    if (StringUtils.containsAny(trim, seps)) {
        ToList lista = new ToList();
        return lista.changeString(trim);
    } else if (false) {

    } else if (NumberUtils.isDigits(trim)) {
        ToInteger toint = new ToInteger();
        return toint.changeString(trim);
    } else if (StringUtils.isAlphanumericSpace(trim)) {
        return data;
    }
    return null;

}

From source file:tweetcrawler.Worker.java

private void workOnFile(File f) {
    String line;//from  w w w.  ja va  2s  .  c  o m
    boolean proceed = false;
    synchronized (Worker.processedFiles) {
        if (!processedFiles.containsKey(f.getAbsolutePath())) {
            processedFiles.put(f.getAbsolutePath(), "started");
            proceed = true;
        }
    }
    if (proceed) {
        try {
            BufferedReader br = getBufferedReaderForCompressedFile(f.getAbsolutePath());
            while ((line = br.readLine()) != null) {
                JSONObject js = new JSONObject(line);
                if (js.has("text")) {
                    line = js.getString("text").toLowerCase();
                    if (StringUtils.contains(line, TweetCrawler.productName)
                            && StringUtils.containsAny(line, TweetCrawler.keywords)
                            && !StringUtils.containsAny(line, TweetCrawler.forbiddenWords)) {
                        for (int i = 0; i < TweetCrawler.keywords.length; i++) {
                            if (StringUtils.contains(line, TweetCrawler.keywords[i])) {
                                TweetCrawler.appendContents(i, stripJSON(js));
                            }
                        }
                    }
                }
            }

            synchronized (Worker.processedFiles) {
                processedFiles.put(f.getAbsolutePath(), "done by " + this.id);
                System.out.println("Thread " + this.id + "\tdid " + f.getPath() + " -- "
                        + 100 * ((double) TweetCrawler.numFilesProcessed++ / TweetCrawler.numFiles)
                        + "% complete");
            }
        } catch (FileNotFoundException ex) {
            System.out.println("File not found: " + f.getAbsolutePath());
        } catch (CompressorException ex) {
            System.out.println("Compressor exception: " + ex.getMessage());
        } catch (IOException ex) {
            System.out.println("Problem reading the file: " + f.getAbsolutePath());
        } catch (JSONException ex) {
            System.out.println("Exception: " + ex.toString());
            TweetCrawler.errOut(id, "Exception:" + ex.toString());
        } catch (ArrayIndexOutOfBoundsException ex) {
            System.out.println("probably corrupted file at " + f.getAbsolutePath() + "Exception:" + ex);
            TweetCrawler.errOut(id,
                    "probably corrupted file at " + f.getAbsolutePath() + "Exception:" + ex.toString());
        } catch (RuntimeException ex) {
            System.out.println("Exception: " + ex.toString());
            TweetCrawler.errOut(id, "Exception:" + ex.toString());
        }
    }
}