Example usage for java.util.regex Matcher groupCount

List of usage examples for java.util.regex Matcher groupCount

Introduction

In this page you can find the example usage for java.util.regex Matcher groupCount.

Prototype

public int groupCount() 

Source Link

Document

Returns the number of capturing groups in this matcher's pattern.

Usage

From source file:net.logstash.logback.pattern.AbstractJsonPatternParser.java

private ValueGetter<?, Event> makeComputableValueGetter(String pattern) {

    Matcher matcher = OPERATION_PATTERN.matcher(pattern);

    if (matcher.matches()) {
        String operationName = matcher.group(1);
        String operationData = matcher.groupCount() > 1 ? matcher.group(2) : null;

        Operation operation = this.operations.get(operationName);
        if (operation != null) {
            if (operation.requiresData() && operationData == null) {
                contextAware.addError("No parameter provided to operation: " + operation.getName());
            } else {
                return operation.createValueGetter(operationData);
            }// www.  j a v  a  2s .  c  o m
        }
    }
    return makeLayoutValueGetter(pattern);
}

From source file:ai.susi.mind.SusiThought.java

/**
 * Create an initial thought using the matcher on an expression.
 * Such an expression is like the input from a text source which contains keywords
 * that are essential for the thought. The matcher extracts such information.
 * Matching informations are named using the order of the appearance of the information pieces.
 * The first information is named '1', the second '2' and so on. The whole information which contained
 * the matching information is named '0'.
 * @param matcher//from  ww  w . j  av a 2s .c  o m
 */
public SusiThought(Matcher matcher) {
    this();
    this.setOffset(0).setHits(1);
    JSONObject row = new JSONObject();
    row.put("0", matcher.group(0));
    for (int i = 0; i < matcher.groupCount(); i++) {
        row.put(Integer.toString(i + 1), matcher.group(i + 1));
    }
    this.setData(new JSONArray().put(row));
}

From source file:jenkins.plugins.pbs.tasks.Qsub.java

private boolean loopSeek(String jobId) {
    boolean toReturn = false;
    while (true) {
        CommandOutput cmd = PBS.traceJob(jobId, numberOfDays);

        final String out = cmd.getOutput();
        // String err = cmd.getError();

        // listener.getLogger().println(out);
        // listener.getLogger().println("----");
        Matcher matcher = JOB_STATUS_REGEX.matcher(out.toString());
        if (matcher.find()) {
            String state = null;/*from   w  w w.  j a v  a 2 s. c  o  m*/
            if (matcher.groupCount() > 2) {
                state = matcher.group(3);
            }
            if (StringUtils.isBlank(state)) {
                state = matcher.group(1);
            }
            listener.getLogger().println("Found job state " + state);
            if ("COMPLETE".equals(state)) {
                // Now we look for the status
                matcher = JOB_SUBSTATUS_REGEX.matcher(out.toString());
                if (matcher.find()) {
                    state = matcher.group(1);
                    listener.getLogger().println("Found run job status of " + state);
                    listener.getLogger().println("---- Remote job output log ----");

                    InputStream outFile = null;
                    try {
                        outFile = Files.newInputStream(Paths.get(this.executionDirectory, "out"));
                        this.outputFileToLogger(outFile);
                    } catch (IOException e) {
                        listener.getLogger().println("ERROR: CANNOT PRINT OUT OUTPUT LOG - " + e.getMessage());
                        e.printStackTrace(listener.getLogger());
                    } finally {
                        IOUtils.closeQuietly(outFile);
                    }

                    listener.getLogger().println("---- End of remote job output log ----");
                    listener.getLogger().println("---- Remote job error log ----");
                    outFile = null;
                    try {
                        outFile = Files.newInputStream(Paths.get(this.executionDirectory, "err"));
                        this.outputFileToLogger(outFile);
                    } catch (IOException e) {
                        listener.getLogger().println("ERROR: CANNOT PRINT OUT ERROR LOG - " + e.getMessage());
                        e.printStackTrace(listener.getLogger());
                    } finally {
                        IOUtils.closeQuietly(outFile);
                    }
                    listener.getLogger().println("---- End of remote job error log ----");

                    // Return error code of the sub job
                    toReturn = "0".equals(state);
                    break;
                }
            }
            break;
        }
        try {
            // listener.getLogger().println("Sleeping for " + span + "ms");
            Thread.sleep(span);
        } catch (InterruptedException e) {
            e.printStackTrace(listener.getLogger());
        }
    }
    // We now know what to return but we can destroy the directory
    try {
        Files.delete(Paths.get(this.executionDirectory, "out"));
        Files.delete(Paths.get(this.executionDirectory, "err"));
    } catch (IOException e) {
        // Ignore
        listener.getLogger().println("Warning: Cannot remove log and/or error files");
        e.printStackTrace(listener.getLogger());
    }
    try {
        Files.delete(Paths.get(this.executionDirectory, "script"));
        Files.delete(Paths.get(this.executionDirectory));
    } catch (IOException e) {
        // Ignore
        listener.getLogger().println("Warning: Cannot remove script and work directory");
        e.printStackTrace(listener.getLogger());
    }
    return toReturn;
}

From source file:net.leegorous.jsc.JavaScriptCombiner.java

protected ArrayList readTestConfig(String content) throws IOException {
    Matcher m = TEST_PATTERN.matcher(content);
    ArrayList paths = null;/*  www.  jav  a2s . c o m*/
    if (m.find()) {
        paths = new ArrayList();
        do {
            if (m.groupCount() > 1) {
                paths.add(m.group(1));
            }
        } while (m.find());
    }

    ArrayList tests = new ArrayList();
    for (int i = 0, j = paths.size(); i < j; i++) {
        String path = paths.get(i).toString();
        File file = this.getRelatedFile(path)[0];

        if (file.isFile())
            tests.add(file);

        if (file.isDirectory()) {
            SubFileFilter filter = new SubFileFilter();
            filter.setDir(file);
            filter.setName("*.js");

            File[] files = file.listFiles(filter);

            for (int k = 0, v = files.length; k < v; k++) {
                tests.add(files[k]);
            }
        }
    }
    return tests;
}

From source file:at.creadoo.util.netio.NetIO.java

/**
 * Returns name for a given port// w ww  . j a  v a 2 s. c  om
 */
public String getPortName(final Integer port) throws NetIOException {
    if (isPortValid(port)) {
        final String response = getPortSetup(port);
        final String regex = "^\"?(.+?)\"?\\s(.+?)\\s(.+?)\\s(.+?)";

        final Pattern pattern = Pattern.compile(regex);
        final Matcher matcher = pattern.matcher(response);

        if (matcher.matches() && matcher.groupCount() == 4) {
            return stripQuotes(matcher.group(1));
        }
    }
    return null;
}

From source file:edu.umd.cs.marmoset.modelClasses.TestOutcome.java

public static FileNameLineNumberPair getFileNameLineNumberPair(String shortTestResult) {
    // TODO handle multi-line FB warnings, and FB warnings w/ no line number
    Pattern pattern = Pattern.compile("At (\\w+\\.java):\\[line (\\d+)\\]");
    Matcher matcher = pattern.matcher(shortTestResult);
    if (matcher.matches() && matcher.groupCount() > 1) {
        String sourceFileName = matcher.group(1);
        String lineNumber = matcher.group(2);
        return new FileNameLineNumberPair(sourceFileName, lineNumber);
    }/*from   ww  w.ja v a 2  s  .c  o m*/
    return null;
}

From source file:com.hangum.tadpole.rdb.core.editors.main.utils.ExtMakeContentAssistUtil.java

/**
 * // w  w w. ja va 2s  .  co m
 * @param userDB
 * @param strQuery
 * @param strCursor
 */
private String getTableColumnAlias(final UserDBDAO userDB, final String strQuery, final String strCursor) {
    List<String> listName = new ArrayList<>();

    TadpoleMetaData dbMetaData = TadpoleSQLManager.getDbMetadata(userDB);
    String strQuote = dbMetaData.getIdentifierQuoteString();
    String strSeparator = ".";
    String strAlias = "";
    if (StringUtils.indexOf(strCursor, strSeparator) != -1) {
        strAlias = StringUtils.substring(strCursor, 0, StringUtils.indexOf(strCursor, strSeparator));
    }

    if (logger.isDebugEnabled()) {
        logger.debug("query is [" + strQuery + "]");
        logger.debug("[quote]" + strQuote + " [alias]" + strAlias);
    }

    String tableNamePattern = "((?:" + strQuote + "(?:[.[^" + strQuote + "]]+)" + strQuote + ")|(?:[\\w"
            + Pattern.quote(strSeparator) + "]+))";
    String structNamePattern;
    if (StringUtils.isEmpty(strAlias)) {
        structNamePattern = "(?:from|update|join|into)\\s*" + tableNamePattern;
    } else {
        structNamePattern = tableNamePattern + "(?:\\s*\\.\\s*" + tableNamePattern + ")?" + "\\s+(?:(?:AS)\\s)?"
                + strAlias + "[\\s,]+";
    }

    try {
        Pattern aliasPattern = Pattern.compile(structNamePattern, Pattern.CASE_INSENSITIVE);
        Matcher matcher = aliasPattern.matcher(strQuery);
        if (!matcher.find()) {
            if (logger.isDebugEnabled())
                logger.debug("=====> Not found match");
            return "";
        }

        if (matcher.groupCount() > 0) {
            for (int i = 1; i <= matcher.groupCount(); i++) {
                listName.add(matcher.group(i));
            }
        } else {
            if (logger.isDebugEnabled())
                logger.debug("=====> Not found object name");
            return "";
        }

    } catch (PatternSyntaxException e) {
        if (logger.isDebugEnabled())
            logger.error("=====> find pattern exception");
        return "";
    }

    // find object column
    StringBuffer strColumnList = new StringBuffer();
    for (String tblName : listName) {
        strColumnList.append(getAssistColumnList(userDB, tblName)).append(_PRE_GROUP);
    }
    return strColumnList.toString();
}

From source file:es.logongas.ix3.security.model.ACE.java

private List<String> getMatcherGroups(Matcher matcher) {
    List<String> matcherGroups = new ArrayList<String>();

    for (int i = 0; i <= matcher.groupCount(); i++) {
        matcherGroups.add(matcher.group(i));
    }/* w  w  w . ja  v a2 s .  c  o  m*/

    return matcherGroups;
}

From source file:com.microsoft.tfs.client.common.ui.helpers.HTMLIncludeHelper.java

/**
 * <p>/* w w w. j  ava2s .  c  o  m*/
 * Transforms the given line, including referenced files by delegating to
 * the {@link HTMLIncludeResourceProvider}.
 * </p>
 *
 * <p>
 * Lines with text matching: %%%INCLUDE(file="filename")%%% will be
 * transformed by replacing the line with the given filename. The "format"
 * tag may also be specified with a value of "text" or "base64". If the
 * format is specified as "text", the file will be reinterpreted while being
 * included (ie, includes in included files will also be included.) If the
 * format is specified as "base64", the file will be included as base64
 * data.
 * </p>
 *
 * <p>
 * Examples:
 * </p>
 *
 * <p>
 * %%%INCLUDE(file="filename")%%% will include the resource specified by
 * "filename".
 * </p>
 *
 * <p>
 * %%%INCLUDE(file="filename", format="text")%%% will include the resource
 * specified by "filename". (This is identical to the above example.)
 * </p>
 *
 * <p>
 * %%%INCLUDE(file="filename", format="base64")%%% will include the base64
 * representation of the resource specified by "filename".
 * </p>
 *
 * @param input
 *        An input line from a resource
 * @return The line with any include statements transformed.
 * @throws IOException
 *         If any included resources could not be read
 */
private String transformIncludes(final String input) throws IOException {
    Check.notNull(input, "input"); //$NON-NLS-1$

    final Matcher includeMatcher = includePattern.matcher(input);
    final StringBuffer transformation = new StringBuffer();

    while (includeMatcher.find()) {
        if (includeMatcher.groupCount() != 1) {
            log.warn(MessageFormat.format("Invalid include statement: {0}", includeMatcher.toString())); //$NON-NLS-1$
            continue;
        }

        final Matcher optionMatcher = optionPattern.matcher(includeMatcher.group(1));
        String resourceName = null;
        String format = "text"; //$NON-NLS-1$

        while (optionMatcher.find()) {
            if (optionMatcher.groupCount() != 2) {
                log.warn(MessageFormat.format("Invalid include statement: {0}", includeMatcher.group(1))); //$NON-NLS-1$
                continue;
            }

            if ("file".equals(optionMatcher.group(1))) //$NON-NLS-1$
            {
                resourceName = optionMatcher.group(2);
            } else if ("format".equals(optionMatcher.group(1))) //$NON-NLS-1$
            {
                format = optionMatcher.group(2);
            }
        }

        if (resourceName == null) {
            log.warn(MessageFormat.format("Invalid include statement: {0}", includeMatcher.group(1))); //$NON-NLS-1$
        } else if ("base64".equals(format)) //$NON-NLS-1$
        {
            includeMatcher.appendReplacement(transformation, readResourceToBase64(resourceName));
        } else {
            includeMatcher.appendReplacement(transformation, readResource(resourceName));
        }
    }

    includeMatcher.appendTail(transformation);

    return transformation.toString();
}

From source file:com.amalto.core.jobox.JobContainer.java

public void removeFromJobLoadersPool(String jobEntityName) {
    // parse name and version
    String jobVersion = StringUtils.EMPTY; //$NON-NLS-1$
    String jobName = StringUtils.EMPTY; //$NON-NLS-1$
    Matcher m = JobAware.jobVersionNamePattern.matcher(jobEntityName);
    while (m.find()) {
        jobName = m.group(1);// w w  w  . j  a v  a 2s.  c  o  m
        jobVersion = m.group(m.groupCount());
    }

    JobInfo jobInfo = new JobInfo(jobName, jobVersion);

    if (this.jobLoadersPool.containsKey(jobInfo)) {
        JobClassLoader jobClassLoader = jobLoadersPool.get(jobInfo);
        LOGGER.info("Removing class loader " + jobClassLoader); //$NON-NLS-1$
        jobLoadersPool.remove(jobInfo);
    }
}