Example usage for java.util.regex Pattern split

List of usage examples for java.util.regex Pattern split

Introduction

In this page you can find the example usage for java.util.regex Pattern split.

Prototype

public String[] split(CharSequence input) 

Source Link

Document

Splits the given input sequence around matches of this pattern.

Usage

From source file:spade.query.common.GetLineage.java

@Override
public Graph execute(String argument_string) {
    Pattern argument_pattern = Pattern.compile(",");
    String[] arguments = argument_pattern.split(argument_string);
    String constraints = arguments[0].trim();
    Map<String, List<String>> parameters = parseConstraints(constraints);
    int maxDepth = Integer.parseInt(arguments[1].trim());
    String direction = arguments[2].trim();

    Graph result = new Graph();
    if (USE_SCAFFOLD && BUILD_SCAFFOLD) {
        result = scaffold.queryManager(parameters);
        return result;
    }/*from w ww . j av  a2  s.c  o m*/

    try {
        String storage = currentStorage.getClass().getSimpleName().toLowerCase();
        String class_prefix = "spade.query." + storage;
        result.setMaxDepth(maxDepth);

        getVertex = (AbstractQuery) Class.forName(class_prefix + ".GetVertex").newInstance();
        getEdge = (AbstractQuery) Class.forName(class_prefix + ".GetEdge").newInstance();
        getChildren = (AbstractQuery) Class.forName(class_prefix + ".GetChildren").newInstance();
        getParents = (AbstractQuery) Class.forName(class_prefix + ".GetParents").newInstance();

        if (DIRECTION_ANCESTORS.startsWith(direction.toLowerCase())
                || DIRECTION_DESCENDANTS.startsWith(direction.toLowerCase())) {
            result = execute(parameters, direction, maxDepth);
        } else if (DIRECTION_BOTH.startsWith(direction.toLowerCase())) {
            direction = DIRECTION_ANCESTORS;
            result = execute(parameters, direction, maxDepth);
            direction = DIRECTION_DESCENDANTS;
            result = Graph.union(result, execute(parameters, direction, maxDepth));
        } else {
            result = null;
        }

        return result;
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Error executing GetLineage setup!", ex);
        return null;
    }
}

From source file:org.apache.giraph.examples.SimpleShortestPathsComputationTest.java

private Map<Long, Double> parseDistances(Iterable<String> results) {
    Map<Long, Double> distances = Maps.newHashMapWithExpectedSize(Iterables.size(results));

    Pattern separator = Pattern.compile("[\t]");

    for (String line : results) {
        String[] tokens = separator.split(line);
        distances.put(Long.parseLong(tokens[0]), Double.parseDouble(tokens[1]));
    }/*from  ww  w. j a va 2  s  .co  m*/
    return distances;
}

From source file:com.jbirdvegas.mgerrit.dialogs.DiffDialog.java

private void setTextView(String result) {
    Pattern pattern = Pattern.compile("\\Qdiff --git \\E");
    String[] filesChanged = pattern.split(result);
    StringBuilder builder = new StringBuilder(0);
    Diff currentDiff = null;//  w w w  .  ja  v a2 s  .  c  o m
    for (String change : filesChanged) {
        String concat;
        try {
            concat = change.substring(2, change.lastIndexOf(mChangedFile.getPath())).trim();
            concat = concat.split(" ")[0];
        } catch (StringIndexOutOfBoundsException notFound) {
            Log.d(TAG, notFound.getMessage());
            continue;
        }
        if (concat.equals(mChangedFile.getPath())) {
            builder.append(DIFF);
            change.replaceAll("\n", mLineSplit);
            currentDiff = new Diff(getContext(), change);
            builder.append(change);
        }
    }
    if (builder.length() == 0) {
        builder.append("Diff not found!");
    }
    // reset text size to default
    mDiffTextView.setTextAppearance(getContext(), android.R.style.TextAppearance_DeviceDefault_Small);
    mDiffTextView.setTypeface(Typeface.MONOSPACE);
    // rebuild text; required to respect the \n
    SpannableString spannableString = currentDiff.getColorizedSpan();
    if (spannableString != null) {
        mDiffTextView.setText(currentDiff.getColorizedSpan(), TextView.BufferType.SPANNABLE);
    } else {
        mDiffTextView.setText("Failed to load diff :(");
    }

}

From source file:org.homemotion.util.impl.IpLocatorImpl.java

/**
 * Other than the getters & setters, this is the only method visible to the
 * outside world/*from  w w  w.  j a v  a  2  s .  c  o m*/
 * 
 * @param ip
 *            The ip address to be located
 * @return IPLocator instance
 * @throws IOException
 *             in case of any error/exception
 */
public IpLocation locate(String ip) throws IOException {
    final String url = HOSTIP_LOOKUP_URL + ip;
    final URL u = new URL(url);
    final List<String> response = getContent(u);

    final Pattern splitterPattern = Pattern.compile(":");
    final IpLocation ipl = new IpLocation();

    for (final String token : response) {
        final String[] keyValue = splitterPattern.split(token);
        if (keyValue.length != 2) {
            continue;
        }

        final String key = StringUtils.upperCase(keyValue[0]);
        final String value = keyValue[1];
        if (KEY_COUNTRY.equals(key)) {
            ipl.setCountry(value);
        } else if (KEY_CITY.equals(key)) {
            ipl.setCity(value);
        } else if (KEY_LATITUDE.equals(key)) {
            ipl.setLatitude(stringToFloat(value));
        } else if (KEY_LONGITUDE.equals(key)) {
            ipl.setLongitude(stringToFloat(value));
        }
    }
    return ipl;
}

From source file:org.openqa.selenium.server.htmlrunner.DatabaseTestResults.java

public String[] splitTestString(String result, String REGEX) {
    //String REGEX = "|";
    Pattern p = Pattern.compile(REGEX);
    return p.split(result);
}

From source file:com.jbirdvegas.mgerrit.DiffViewer.java

private void setTextView(String result) {
    Pattern pattern = Pattern.compile("\\Qdiff --git \\E");
    String[] filesChanged = pattern.split(result);
    StringBuilder builder = new StringBuilder(0);
    for (String change : filesChanged) {
        String concat;/*from   w w  w  .  ja va2  s  .c o m*/
        int index = change.lastIndexOf(mFilePath);
        if (index < 0)
            continue;

        concat = change.substring(2, index).trim().split(" ", 2)[0];
        if (concat.equals(mFilePath)) {
            change.replaceAll("\n", mLineSplit);
            builder.append(change);
        }
    }
    if (builder.length() == 0) {
        builder.append("Diff not found!");
    } else {
        // reset text size to default
        mDiffTextView.setTextAppearance(this, android.R.style.TextAppearance_DeviceDefault_Small);
        mDiffTextView.setTypeface(Typeface.MONOSPACE);
    }
    // rebuild text; required to respect the \n
    mDiffTextView.setDiffText(builder.toString());
}

From source file:fr.paris.lutece.plugins.profanityfilter.service.ProfanityFilter.java

@Override
public ProfanityResult checkString(String str) {
    ProfanityResult profResult = new ProfanityResult();
    String[] wordStr = null;//ww  w .j a  v a2s .  co  m
    Pattern p = Pattern.compile("\\W");
    Collection<Word> wordList = WordHome.getWordsList();

    if ((str != null) && StringUtils.isNotEmpty(str) && StringUtils.isNotBlank(str)) {
        wordStr = p.split(str);
    }

    boolean _isSwearWords = false;
    int number = 0;

    if (wordStr != null) {
        for (String word : wordStr) {
            if (containsReferenceTo(wordList, word)) {
                profResult.addWord(word);
                _isSwearWords = true;
                number++;
            }
        }
    }

    profResult.setIsSwearWords(_isSwearWords);
    profResult.setNumberSwearWords(number);

    return profResult;
}

From source file:org.radeox.filter.ParagraphFilter.java

public String simpleFilter(String input, FilterContext context) {

    log.debug("Paragraph Filter Input " + input);
    Pattern patternBreaks = Pattern.compile(breaksRE);

    // attempts to locate lin breaks in the content with ([ \t\r]*[\n]){2}
    String[] p = patternBreaks.split(input);
    if (p.length == 1) {
        // only 1, therefor no embeded paragraphs
        return input;
    }//  w  ww .j av  a  2 s . c  o m

    StringBuffer sb = new StringBuffer();
    int nsplits = 0;
    for (int i = 0; i < p.length; i++) {
        if (nsplits == 0) {
            sb.append(replaceFirst);
            nsplits++;
        } else {
            sb.append(replaceAll);
            nsplits++;
        }
        sb.append(p[i]);
    }

    if (nsplits > 0) {
        sb.append(replaceLast);
        nsplits++;
    }
    String output = sb.toString();
    log.debug("Paragraph Filter Input " + output);

    return output;
}

From source file:org.ala.preprocess.ColFamilyNamesProcessor.java

/**
 * Process a single file./*w w w  . j av  a2  s.  co  m*/
 * 
 * @param filePath
 * @param uri
 * @param publisher
 * @param source
 * @throws FileNotFoundException
 * @throws Exception
 * @throws IOException
 * @throws RDFHandlerException
 */
private void processFile(String filePath, String uri, String publisher, String source)
        throws FileNotFoundException, Exception, IOException, RDFHandlerException {
    //copy the raw file to the repository
    int documentId = copyRawFileToRepo(filePath, uri, "http://www.catalogueoflife.org/", "text/plain");

    //set the dublin core
    Map<String, String> dc = new HashMap<String, String>();
    dc.put(Predicates.DC_IDENTIFIER.toString(), uri);
    dc.put(Predicates.DC_PUBLISHER.toString(), publisher);
    dc.put(Predicates.DC_SOURCE.toString(), uri);
    dc.put(Predicates.DC_FORMAT.toString(), "text/plain");
    repository.storeDublinCore(documentId, dc);

    //reset the reader so it can be read again
    Reader r = new FileReader(filePath);

    //write the triples out
    DocumentOutputStream rdfDos = repository.getRDFOutputStream(documentId);

    //read file, creating the turtle
    CSVReader csvr = new CSVReader(r, '\t');
    String[] fields = null;

    final RDFWriter rdfWriter = new TurtleWriter(new OutputStreamWriter(rdfDos.getOutputStream()));
    rdfWriter.startRDF();
    Pattern p = Pattern.compile(",");

    String subject = MappingUtils.getSubject();
    while ((fields = csvr.readNext()) != null) {
        if (fields.length == NO_OF_COLUMNS) {

            String[] commonNames = p.split(fields[0]);
            for (String commonName : commonNames) {
                subject = MappingUtils.getNextSubject(subject);
                BNode bnode = new BNodeImpl(subject);
                rdfWriter.handleStatement(new StatementImpl(bnode,
                        new URIImpl(Predicates.COMMON_NAME.toString()), new LiteralImpl(commonName.trim())));

                rdfWriter.handleStatement(new StatementImpl(bnode,
                        new URIImpl(Predicates.SCIENTIFIC_NAME.toString()), new LiteralImpl(fields[1])));

                rdfWriter.handleStatement(new StatementImpl(bnode, new URIImpl(Predicates.KINGDOM.toString()),
                        new LiteralImpl(fields[2])));
            }
        } else {
            logger.warn("Error reading from file. Was expecting " + NO_OF_COLUMNS + ", got " + fields.length);
        }
        subject = MappingUtils.getNextSubject(subject);
    }
    rdfWriter.endRDF();

    //tied up the output stream
    rdfDos.getOutputStream().flush();
    rdfDos.getOutputStream().close();
}

From source file:it.cnr.icar.eric.server.interfaces.rest.FilePathURLHandler.java

private String[] getPathElements(String pathInfo) {
    String[] pathElements = null;

    Pattern p = Pattern.compile("/");
    if (pathInfo.charAt(0) == '/') {
        pathInfo = pathInfo.substring(1);
    }//from w  w w.  j  av  a2  s. c om
    pathElements = p.split(pathInfo);

    return pathElements;
}