Example usage for java.util.regex Matcher end

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

Introduction

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

Prototype

public int end() 

Source Link

Document

Returns the offset after the last character matched.

Usage

From source file:com.thero.framework.util.AntPathStringMatcher.java

private Pattern createPattern(String pattern) {
    StringBuilder patternBuilder = new StringBuilder();
    Matcher m = GLOB_PATTERN.matcher(pattern);
    int end = 0;/*from  ww w  .j  a  v a2 s.  co  m*/
    while (m.find()) {
        patternBuilder.append(quote(pattern, end, m.start()));
        String match = m.group();
        if ("?".equals(match)) {
            patternBuilder.append('.');
        } else if ("*".equals(match)) {
            patternBuilder.append(".*");
        } else if (match.startsWith("{") && match.endsWith("}")) {
            int colonIdx = match.indexOf(':');
            if (colonIdx == -1) {
                patternBuilder.append(DEFAULT_VARIABLE_PATTERN);
                variableNames.add(m.group(1));
            } else {
                String variablePattern = match.substring(colonIdx + 1, match.length() - 1);
                patternBuilder.append('(');
                patternBuilder.append(variablePattern);
                patternBuilder.append(')');
                String variableName = match.substring(1, colonIdx);
                variableNames.add(variableName);
            }
        }
        end = m.end();
    }
    patternBuilder.append(quote(pattern, end, pattern.length()));
    return Pattern.compile(patternBuilder.toString());
}

From source file:tr.edu.gsu.nerwip.recognition.internal.modelless.subee.Subee.java

/**
 * Receives the entities detected thanks to the hyperlinks, and tries 
 * to find their other occurrences in the text.
 * //from ww w .  j  ava2 s.  c o m
 * @param article 
 *       Article to process.
 * @param sureEntities 
 *       Entities already detected, corresponding to hyperlinks.
 * @return
 *       A new list of possible entities, to be merged later with the sure entities.
 */
private List<AbstractEntity<?>> processOccurrences(Article article, List<AbstractEntity<?>> sureEntities) {
    logger.increaseOffset();
    String rawText = article.getRawText();
    List<AbstractEntity<?>> result = new ArrayList<AbstractEntity<?>>();

    //      // sort entities by type (we want to prioritize them)
    //      logger.log("Sort entity by type");
    //      TreeSet<AbstractEntity<?>> temp = new TreeSet<AbstractEntity<?>>(new Comparator<AbstractEntity<?>>()
    //      {   @Override
    //         public int compare(AbstractEntity<?> o1, AbstractEntity<?> o2)
    //         {   int result = 0;
    //            EntityType t1 = o1.getType();
    //            EntityType t2 = o2.getType();
    //            if(t1==EntityType.ORGANIZATION && t2!=EntityType.ORGANIZATION
    //               || t1==EntityType.PERSON && t2==EntityType.LOCATION)
    //               result = -1;
    //            else if(t2==EntityType.ORGANIZATION && t1!=EntityType.ORGANIZATION
    //                  || t2==EntityType.PERSON && t1==EntityType.LOCATION)
    //               result = 1;
    //            else
    //               result = o1.compareTo(o2);
    //            return result;
    //         }   
    //      });
    //      temp.addAll(sureEntities);

    // look for additional occurrences
    logger.log("Look for additional occurrences");
    for (AbstractEntity<?> entity : sureEntities) {
        String valueStr = entity.getStringValue();

        // look for the entity in the text
        String escapedStr = Pattern.quote(valueStr);
        Pattern p = Pattern.compile("\\b" + escapedStr + "\\b");
        Matcher m = p.matcher(rawText);
        while (m.find()) {
            int startPos = m.start();
            //            // don't use the same position for several entities
            //            if(!positionAlreadyUsed(startPos, result))   // this test is now done later 
            {
                int endPos = m.end();
                EntityType type = entity.getType();
                AbstractEntity<?> ent = AbstractEntity.build(type, startPos, endPos, RecognizerName.SUBEE,
                        valueStr);
                result.add(ent);
            }
        }
    }

    logger.decreaseOffset();
    return result;
}

From source file:com.manydesigns.portofino.pageactions.text.TextAction.java

protected String restoreAttachmentUrls(String content) {
    Pattern pattern = Pattern.compile(PORTOFINO_ATTACHMENT_PATTERN);
    Matcher matcher = pattern.matcher(content);
    int lastEnd = 0;
    StringBuilder sb = new StringBuilder();
    while (matcher.find()) {
        String attachmentId = matcher.group(1);
        //Default to src for old texts
        String hrefAttribute = (matcher.groupCount() >= 3 && matcher.group(3) != null) ? matcher.group(3)
                : "src";

        sb.append(content.substring(lastEnd, matcher.start())).append(hrefAttribute).append("=\"")
                .append(StringEscapeUtils.escapeHtml(generateViewAttachmentUrl(attachmentId))).append("\"");

        lastEnd = matcher.end();
    }/*from w  ww.  j a  v  a2 s  .co m*/
    sb.append(content.substring(lastEnd));
    return sb.toString();
}

From source file:gtu._work.ui.RegexDirReplacer.java

/**
 * @param fromPattern//  w  w w .j  a  v a  2 s . c  o m
 *            ???pattern
 * @param toFormat
 *            ??pattern
 * @param replaceText
 *            ??
 */
String replacer(String fromPattern, String toFormat, String replaceText, File file) {
    String errorRtn = replaceText.toString();
    try {
        Pattern pattern = Pattern.compile(fromPattern);
        Matcher matcher = pattern.matcher(replaceText);

        StringBuilder sb = new StringBuilder();
        int startPos = 0;

        String tempStr = null;
        for (; matcher.find();) {
            tempStr = toFormat.toString();
            sb.append(replaceText.substring(startPos, matcher.start()));
            for (int ii = 0; ii <= matcher.groupCount(); ii++) {
                tempStr = tempStr.replaceAll("#" + ii + "#", Matcher.quoteReplacement(matcher.group(ii)));
                System.out.println("group[" + ii + "] -- " + matcher.group(ii) + "\t--> " + tempStr);
            }
            sb.append(tempStr);
            startPos = matcher.end();
        }

        sb.append(replaceText.substring(startPos));

        return sb.toString();
    } catch (Exception ex) {
        // JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog(ex.getMessage(),
        // getTitle());
        errMsg.append(file.getName() + ":" + ex + "\n");
        return errorRtn;
    }
}

From source file:com.joliciel.frenchTreebank.export.FrenchTreebankTokenReader.java

PosTagSequence nextSentenceInternal() {
    MONITOR.startTask("nextSentenceInternal");
    try {/* w  w w  .  j  a va 2s.com*/
        Sentence sentence = treebankReader.nextSentence();
        LOG.debug("Sentence " + sentence.getSentenceNumber());
        List<Integer> tokenSplits = new ArrayList<Integer>();
        PosTagSet posTagSet = TalismaneSession.getPosTagSet();

        String text = sentence.getText();
        // get rid of duplicate white space
        Pattern duplicateWhiteSpace = Pattern.compile("\\s[\\s]+");
        text = duplicateWhiteSpace.matcher(text).replaceAll(" ");

        // there's no guarantee that the phrase units align to the original sentence text
        // given the issues we had for aligning sentences in the first place
        List<PhraseUnit> phraseUnits = sentence.getAllPhraseUnits();
        LOG.trace("Phrase units: " + phraseUnits.size());
        Pattern separators = Tokeniser.SEPARATORS;
        Pattern whitespace = Pattern.compile("\\s+");

        Matcher matcher = separators.matcher(text);
        List<String> allTokens = new ArrayList<String>();
        int currentPos = 0;
        while (matcher.find()) {
            if (matcher.start() > currentPos) {
                String leftoverToken = text.substring(currentPos, matcher.start());
                allTokens.add(leftoverToken);
            }
            String token = text.substring(matcher.start(), matcher.end());
            allTokens.add(token);
            currentPos = matcher.end();
        }
        if (currentPos < text.length())
            allTokens.add(text.substring(currentPos));

        com.joliciel.talismane.filters.Sentence oneSentence = this.filterService.getSentence(text);
        TokenSequence tokenSequence = this.tokeniserService.getTokenSequence(oneSentence);
        List<PosTaggedToken> posTaggedTokens = new ArrayList<PosTaggedToken>();

        PhraseUnitReader phraseUnitReader = new ComplexPhraseUnitReaderWithEmptyTokens(phraseUnits);

        phraseUnitReader.setTreebankService(treebankService);
        if (ftbPosTagMapper != null)
            phraseUnitReader.setFtbPosTagMapper(ftbPosTagMapper);

        String phraseUnitText = phraseUnitReader.nextString();

        LOG.trace("phrase unit: " + phraseUnitText);
        currentPos = 0;
        int lastSplit = 0;
        tokenSplits.add(0);

        while (phraseUnitText != null && phraseUnitText.length() == 0) {
            tokenSplits.add(currentPos);
            Token aToken = tokenSequence.addEmptyToken(currentPos);
            PosTag posTag = phraseUnitReader.getPosTag();
            Decision<PosTag> corpusDecision = posTagSet.createDefaultDecision(posTag);

            PosTaggedToken posTaggedToken = posTaggerService.getPosTaggedToken(aToken, corpusDecision);
            posTaggedTokens.add(posTaggedToken);
            phraseUnitText = phraseUnitReader.nextString();
        }
        boolean inPhraseUnit = false;
        boolean addEmptyTokenBeforeNextToken = false;
        PosTag emptyTokenPosTag = null;
        for (String token : allTokens) {
            if (LOG.isTraceEnabled())
                LOG.trace("token: " + token);
            currentPos += token.length();
            if ((!ignoreCase && phraseUnitText.equals(token))
                    || (ignoreCase && phraseUnitText.equalsIgnoreCase(token))) {
                // exact match

                if (addEmptyTokenBeforeNextToken) {
                    if (LOG.isTraceEnabled())
                        LOG.trace("Adding empty token at " + (currentPos - token.length()));
                    tokenSplits.add((currentPos - token.length()));
                    Token emptyToken = tokenSequence.addEmptyToken((currentPos - token.length()));
                    Decision<PosTag> emptyTokenDecision = posTagSet.createDefaultDecision(emptyTokenPosTag);
                    PosTaggedToken posTaggedToken2 = posTaggerService.getPosTaggedToken(emptyToken,
                            emptyTokenDecision);
                    posTaggedTokens.add(posTaggedToken2);
                    addEmptyTokenBeforeNextToken = false;
                }

                if (LOG.isTraceEnabled())
                    LOG.trace("Adding split " + currentPos);
                tokenSplits.add(currentPos);

                Token aToken = tokenSequence.addToken(lastSplit, currentPos);
                PosTag posTag = phraseUnitReader.getPosTag();
                Decision<PosTag> corpusDecision = posTagSet.createDefaultDecision(posTag);
                PosTaggedToken posTaggedToken = posTaggerService.getPosTaggedToken(aToken, corpusDecision);
                posTaggedTokens.add(posTaggedToken);

                lastSplit = currentPos;
                phraseUnitText = phraseUnitReader.nextString();
                if (LOG.isTraceEnabled())
                    LOG.trace("phrase unit: " + phraseUnitText);
                while (phraseUnitText != null && phraseUnitText.length() == 0) {
                    Token emptyToken = null;
                    emptyTokenPosTag = phraseUnitReader.getPosTag();
                    phraseUnitText = phraseUnitReader.nextString();
                    if (LOG.isTraceEnabled())
                        LOG.trace("phrase unit: " + phraseUnitText);

                    // Empty tokens need to be attached either to the right (auquel, duquel)
                    // or to the left (du, des)
                    if (phraseUnitText.equals("duquel") || phraseUnitText.equals("auquel")
                            || phraseUnitText.equals("desquels") || phraseUnitText.equals("auxquels")
                            || phraseUnitText.equals("desquelles") || phraseUnitText.equals("auxquelles")) {
                        // attach empty token to the "duquel" that follows it
                        addEmptyTokenBeforeNextToken = true;
                    } else {
                        if (LOG.isTraceEnabled())
                            LOG.trace("Adding empty token at " + currentPos);
                        tokenSplits.add(currentPos);
                        emptyToken = tokenSequence.addEmptyToken(currentPos);
                        Decision<PosTag> emptyTokenDecision = posTagSet.createDefaultDecision(emptyTokenPosTag);
                        PosTaggedToken posTaggedToken2 = posTaggerService.getPosTaggedToken(emptyToken,
                                emptyTokenDecision);
                        posTaggedTokens.add(posTaggedToken2);
                    }
                }
                inPhraseUnit = false;
            } else if (phraseUnitText.length() >= token.length() && ((!ignoreCase
                    && phraseUnitText.substring(0, token.length()).equals(token))
                    || (ignoreCase && phraseUnitText.substring(0, token.length()).equalsIgnoreCase(token)))) {
                // the current phrase unit text starts with this token
                phraseUnitText = phraseUnitText.substring(token.length());
                if (LOG.isTraceEnabled())
                    LOG.trace("phrase unit: " + phraseUnitText);
                inPhraseUnit = true;
            } else if (token.length() == 1 && whitespace.matcher(token).matches()) {
                // white space, always add split unless we're already inside white space
                if (!inPhraseUnit) {
                    if (LOG.isTraceEnabled())
                        LOG.trace("Adding split " + currentPos);
                    tokenSplits.add(currentPos);
                    tokenSequence.addToken(lastSplit, currentPos);
                    lastSplit = currentPos;
                }
            } else {
                // non-white space, what to do? either we skip the token, or we skip the phrase unit!
                // for now let's assume it never happens and see what results!
                int pos = 0;
                StringBuilder sb = new StringBuilder();
                for (int split : tokenSplits) {
                    String aToken = text.substring(pos, split);
                    sb.append('|');
                    sb.append(aToken);
                    pos = split;
                }
                LOG.info(sb.toString());
                LOG.info("File: " + sentence.getFile().getFileName());
                LOG.info("Sentence: " + text);
                if (csvFileErrorWriter != null) {
                    try {
                        csvFileErrorWriter.write(CSVFormatter.format(phraseUnitText) + ",");
                        for (String info : phraseUnitReader.getCurrentInfo())
                            csvFileErrorWriter.write(CSVFormatter.format(info) + ",");
                        csvFileErrorWriter.write(CSVFormatter.format(token) + ",");
                        csvFileErrorWriter.write(sentence.getFile().getFileName() + ",");
                        csvFileErrorWriter.write(sentence.getSentenceNumber() + ",");
                        csvFileErrorWriter.write(CSVFormatter.format(sentence.getText()) + ",");
                        csvFileErrorWriter.write("\n");
                        csvFileErrorWriter.flush();
                    } catch (IOException ioe) {
                        throw new RuntimeException(ioe);
                    }
                    break;
                } else {
                    // instead of throwing an error, write these to a file (or do both)
                    // so we can catch them all in one fell swoop
                    throw new RuntimeException("Unexpected text: " + token);
                }
            }
        }
        if (lastSplit < currentPos) {
            tokenSplits.add(currentPos);
        }

        if (LOG.isDebugEnabled()) {
            LOG.debug(text);

            int pos = 0;
            StringBuilder sb = new StringBuilder();
            for (int split : tokenSplits) {
                String aToken = text.substring(pos, split);
                sb.append('|');
                sb.append(aToken);
                pos = split;
            }
            LOG.debug(sb.toString());
        }

        for (TokenSequenceFilter tokenSequenceFilter : this.tokenSequenceFilters) {
            if (LOG.isTraceEnabled())
                LOG.trace("Applying filter: " + tokenSequenceFilter.getClass().getSimpleName());
            tokenSequenceFilter.apply(tokenSequence);
        }

        if (tokenFilterWrapper == null) {
            tokenFilterWrapper = tokenFilterService.getTokenSequenceFilter(this.tokenFilters);
        }
        tokenFilterWrapper.apply(tokenSequence);

        tokenSequence.finalise();

        PosTagSequence posTagSequence = this.posTaggerService.getPosTagSequence(tokenSequence,
                allTokens.size() / 2);
        int i = 0;
        for (Token token : tokenSequence) {
            if (LOG.isTraceEnabled())
                LOG.trace("Token : \"" + token.getText() + "\" (was \"" + token.getOriginalText() + "\")");
            PosTaggedToken posTaggedToken = posTaggedTokens.get(i);
            if (token.equals(posTaggedToken.getToken())) {
                posTagSequence.addPosTaggedToken(posTaggedToken);
                i++;
            } else if (token.getStartIndex() == token.getEndIndex()) {
                LOG.debug("Adding null pos tag at position " + token.getStartIndex());
                Decision<PosTag> nullPosTagDecision = posTagSet.createDefaultDecision(PosTag.NULL_POS_TAG);
                PosTaggedToken emptyTagToken = posTaggerService.getPosTaggedToken(token, nullPosTagDecision);
                posTagSequence.addPosTaggedToken(emptyTagToken);
            } else {
                throw new RuntimeException("Expected only empty tokens added. Postag Token = "
                        + posTaggedToken.getToken().getText() + ", start: " + token.getStartIndex() + ", end:"
                        + token.getEndIndex());
            }
        }

        if (useCompoundPosTags) {
            PosTagSequence newSequence = this.posTaggerService.getPosTagSequence(tokenSequence,
                    allTokens.size() / 2);
            PosTaggedToken lastPosTaggedToken = null;
            i = 0;
            for (PosTaggedToken posTaggedToken : posTagSequence) {
                boolean removed = false;
                if (posTaggedToken.getToken().isEmpty()) {
                    String lastWord = "";
                    if (lastPosTaggedToken != null)
                        lastWord = lastPosTaggedToken.getToken().getOriginalText().toLowerCase();
                    if (lastWord.equals("des") || lastWord.equals("du") || lastWord.equals("aux")
                            || lastWord.equals("au") || lastWord.endsWith(" des") || lastWord.endsWith(" du")
                            || lastWord.endsWith(" aux") || lastWord.endsWith(" au")
                            || lastWord.endsWith("'aux") || lastWord.endsWith("'au")) {
                        if (lastWord.equals("des") || lastWord.equals("du") || lastWord.equals("aux")
                                || lastWord.equals("au")) {
                            if (lastPosTaggedToken.getTag().getCode().equals("P")) {
                                lastPosTaggedToken.setTag(posTagSet.getPosTag("P+D"));
                                lastPosTaggedToken.getToken().setText(lastWord);
                            }
                        }
                        posTaggedToken.setTag(PosTag.NULL_POS_TAG);
                        tokenSequence.removeEmptyToken(posTaggedToken.getToken());
                        removed = true;
                    } else if (i == posTagSequence.size() - 1) {
                        // last token in sequence
                        // need to remove it now, since it won't get removed in the next iteration
                        tokenSequence.removeEmptyToken(posTaggedToken.getToken());
                        removed = true;
                    }
                } else {
                    newSequence.addPosTaggedToken(posTaggedToken);
                }
                if (lastPosTaggedToken != null && lastPosTaggedToken.getToken().isEmpty()) {
                    String word = posTaggedToken.getToken().getOriginalText().toLowerCase();
                    if (word.equals("duquel") || word.equals("desquels") || word.equals("desquelles")
                            || word.equals("auquel") || word.equals("auxquels") || word.equals("auxquelles")) {
                        posTaggedToken.setTag(posTagSet.getPosTag("P+PRO"));
                        lastPosTaggedToken.setTag(PosTag.NULL_POS_TAG);
                        posTaggedToken.getToken().setText(word);
                        tokenSequence.removeEmptyToken(lastPosTaggedToken.getToken());
                    } else if (word.equals("dudit")) {
                        posTaggedToken.setTag(posTagSet.getPosTag("P+D"));
                        lastPosTaggedToken.setTag(PosTag.NULL_POS_TAG);
                        posTaggedToken.getToken().setText(word);
                        tokenSequence.removeEmptyToken(lastPosTaggedToken.getToken());
                    } else {
                        LOG.info("Not expecting empty token here (index "
                                + lastPosTaggedToken.getToken().getIndex() + ", next token = " + word + "): "
                                + posTagSequence);
                        lastPosTaggedToken.setTag(PosTag.NULL_POS_TAG);
                        tokenSequence.removeEmptyToken(lastPosTaggedToken.getToken());
                    }
                }
                if (!removed)
                    lastPosTaggedToken = posTaggedToken;
                i++;
            }
            posTagSequence = newSequence;
            tokenSequence.finalise();
        }
        for (PosTagSequenceFilter posTagSequenceFilter : this.posTagSequenceFilters) {
            posTagSequenceFilter.apply(posTagSequence);
        }

        return posTagSequence;
    } finally {
        MONITOR.endTask("nextSentenceInternal");
    }
}

From source file:com.stealthyone.mcb.mcml.MCMLBuilder.java

public MCMLBuilder(String input, Map<String, Object> replacements) {
    Validate.notNull(input, "Input cannot be null.");

    this.rawText = input;

    if (this.replacements != null && replacements != null) {
        this.replacements.putAll(replacements);

        for (Entry<String, Object> entry : replacements.entrySet()) {
            if (entry.getValue() instanceof String) {
                this.rawText = rawText.replace(entry.getKey(), (String) entry.getValue());
            }/*from  w ww  .  j av a2  s  .c  o  m*/
        }
    }

    this.rawText = rawText.replace(ChatColor.COLOR_CHAR, '&');

    // Identify text groups
    int lastIndex = 0;

    final Matcher matcher = PATTERN_TEXT_GROUP.matcher(input);
    while (matcher.find()) {
        TempPart part = new TempPart(matcher.group(1));
        if (!parts.isEmpty()) {
            TempPart prevPart = parts.get(parts.size() - 1);
            TextPiece lastPiece = prevPart.text.get(prevPart.text.size() - 1);

            for (TextPiece piece : part.text) {
                if (piece.color == null) {
                    piece.color = lastPiece.color;
                    piece.italicize = lastPiece.italicize;
                    piece.bold = lastPiece.bold;
                    piece.underline = lastPiece.underline;
                    piece.strikeout = lastPiece.strikeout;
                    piece.magic = lastPiece.magic;
                }
            }

        }

        if (matcher.start() > lastIndex) {
            // Handle ungrouped text
            TempPart ungroupedPart = new TempPart(rawText.substring(lastIndex, matcher.start()));

            parts.add(ungroupedPart);
        }

        lastIndex = matcher.end();

        // Check for event
        int offset = rawText.length() - input.substring(lastIndex).length();
        final Matcher eventMatcher = PATTERN_EVENT.matcher(input.substring(lastIndex));
        if (eventMatcher.find()) {
            handleEvent(part, eventMatcher);

            lastIndex = eventMatcher.end() + offset;

            offset = rawText.length() - input.substring(lastIndex).length();
            final Matcher secEventMatcher = PATTERN_EVENT.matcher(input.substring(lastIndex));
            if (secEventMatcher.find()) {
                handleEvent(part, secEventMatcher);

                lastIndex = secEventMatcher.end() + offset;
            }
        }

        parts.add(part);
    }

    if (lastIndex != rawText.length()) {
        TempPart ungroupedPart = new TempPart(rawText.substring(lastIndex));

        if (!parts.contains(ungroupedPart)) {
            parts.add(ungroupedPart);
        }
    }
}

From source file:com.microsoft.gittf.core.tasks.CheckinHeadCommitTask.java

/**
 * Parses the comments of the commits to list the mentioned work items
 *///from  w  ww  . jav  a 2 s.c o  m
private WorkItemCheckinInfo[] getWorkItems(final TaskProgressMonitor progressMonitor,
        final String commitComment, final boolean isLastCommit) throws Exception {

    List<WorkItemCheckinInfo> workItemsCheckinInfo = new ArrayList<WorkItemCheckinInfo>();
    if (mentions) {
        final String REGEX = "(\\s|^)#\\d+(\\s|$)(#\\d+(\\s|$))*"; //$NON-NLS-1$
        if (commitComment != null && commitComment.length() > 0) {
            final Pattern pattern = Pattern.compile(REGEX);
            // get a matcher object
            final Matcher patternMatcher = pattern.matcher(commitComment);
            while (patternMatcher.find()) {

                final String workItemIDREGEX = "#\\d+"; //$NON-NLS-1$
                final Pattern workItemIDPattern = Pattern.compile(workItemIDREGEX);
                final String workItemIDString = commitComment.substring(patternMatcher.start(),
                        patternMatcher.end());
                final Matcher workItemIDMatcher = workItemIDPattern.matcher(workItemIDString);
                while (workItemIDMatcher.find()) {
                    final WorkItem workitem = getWorkItem(progressMonitor,
                            workItemIDString.substring(workItemIDMatcher.start(), workItemIDMatcher.end()));
                    if (workitem != null) {
                        final WorkItemCheckinInfo workItemCheckinInfo = new WorkItemCheckinInfo(workitem,
                                CheckinWorkItemAction.ASSOCIATE);
                        if (!workItemsCheckinInfo.contains(workItemCheckinInfo)) {
                            workItemsCheckinInfo.add(workItemCheckinInfo);
                        }
                    }
                }

            }
        }
    }
    if (isLastCommit) {
        // If there were no work items in the comments
        if (workItemsCheckinInfo.isEmpty()) {
            return workItems;
        }

        for (final WorkItemCheckinInfo workItem : workItems) {
            if (!workItemsCheckinInfo.contains(workItem)) {
                workItemsCheckinInfo.add(workItem);
            }
        }
    }
    return workItemsCheckinInfo.toArray(new WorkItemCheckinInfo[workItemsCheckinInfo.size()]);
}

From source file:com.juick.android.MessageMenu.java

protected void collectURLs(String source, MessageID mid) {
    if (urls == null)
        urls = new ArrayList<String>();
    ArrayList<ExtractURLFromMessage.FoundURL> foundURLs = ExtractURLFromMessage.extractUrls(source, mid);
    for (ExtractURLFromMessage.FoundURL foundURL : foundURLs) {
        urls.add(foundURL.url);/*from www  .j  a v a 2  s  .c o  m*/
    }
    int pos = 0;
    Matcher m = JuickMessagesAdapter.getCrossReferenceMsgPattern(mid).matcher(source);
    while (m.find(pos)) {
        urls.add(source.substring(m.start(), m.end()));
        pos = m.end();
    }
}

From source file:com.application.utils.FastDateParser.java

/**
 * Initialize derived fields from defining fields.
 * This is called from constructor and from readObject (de-serialization)
 *
 * @param definingCalendar the {@link java.util.Calendar} instance used to initialize this FastDateParser
 *//*from w  ww  .j av a  2 s.  c  o  m*/
private void init(Calendar definingCalendar) {

    final StringBuilder regex = new StringBuilder();
    final List<Strategy> collector = new ArrayList<Strategy>();

    final Matcher patternMatcher = formatPattern.matcher(pattern);
    if (!patternMatcher.lookingAt()) {
        throw new IllegalArgumentException(
                "Illegal pattern character '" + pattern.charAt(patternMatcher.regionStart()) + "'");
    }

    currentFormatField = patternMatcher.group();
    Strategy currentStrategy = getStrategy(currentFormatField, definingCalendar);
    for (;;) {
        patternMatcher.region(patternMatcher.end(), patternMatcher.regionEnd());
        if (!patternMatcher.lookingAt()) {
            nextStrategy = null;
            break;
        }
        final String nextFormatField = patternMatcher.group();
        nextStrategy = getStrategy(nextFormatField, definingCalendar);
        if (currentStrategy.addRegex(this, regex)) {
            collector.add(currentStrategy);
        }
        currentFormatField = nextFormatField;
        currentStrategy = nextStrategy;
    }
    if (patternMatcher.regionStart() != patternMatcher.regionEnd()) {
        throw new IllegalArgumentException(
                "Failed to parse \"" + pattern + "\" ; gave up at index " + patternMatcher.regionStart());
    }
    if (currentStrategy.addRegex(this, regex)) {
        collector.add(currentStrategy);
    }
    currentFormatField = null;
    strategies = collector.toArray(new Strategy[collector.size()]);
    parsePattern = Pattern.compile(regex.toString());
}

From source file:at.ac.tuwien.inso.subcat.utility.commentparser.Parser.java

License:asdf

private void parseQuotes(List<ContentNode<T>> ast, String comment) {
    Matcher m = pQuote.matcher(comment);

    int lastEnd = 0;
    while (m.find()) {
        if (lastEnd >= 0 && lastEnd != m.start()) {
            parseParagraphs(ast, comment.substring(lastEnd, m.start()));
        }// w  w w .  ja  v  a 2  s  . c o m

        String content = m.group(0);
        String idStr = m.group(2);
        int id = (idStr != null) ? Integer.parseInt(idStr) : -1;

        Matcher cfm = pCleanFstQuote.matcher(content);
        content = cfm.replaceAll("");

        Matcher csm = pCleanSubQuote.matcher(content);
        content = csm.replaceAll("");

        String[] contentFragments = pQuoteSplitter.split(content.trim());
        String[] cleanedFragments = new String[contentFragments.length];
        for (int i = 0; i < contentFragments.length; i++) {
            Matcher normM = pNorm.matcher(contentFragments[i]);
            cleanedFragments[i] = normM.replaceAll(" ");
        }

        ast.add(new QuoteNode<T>(cleanedFragments, id));
        lastEnd = m.end();
    }

    if (lastEnd != comment.length()) {
        String frag = comment.substring(lastEnd, comment.length());
        if (frag.trim().length() > 0) {
            parseGLibMessages(ast, frag);
        }
    }
}