List of usage examples for java.util.regex Matcher groupCount
public int groupCount()
From source file:edu.umd.cs.marmoset.modelClasses.TestOutcome.java
public FileNameLineNumberPair getFileNameLineNumberPair() { if (getTestType().equals(FINDBUGS)) { return getFileNameLineNumberPair(getShortTestResult()); } else if (getTestType().equals(PUBLIC) || getTestType().equals(RELEASE) || getTestType().equals(SECRET)) { BufferedReader reader = null; Pattern pattern = Pattern.compile("\\((\\w+\\.java):(\\d+)\\)"); try {//from w ww .j av a 2 s. c o m reader = new BufferedReader(new StringReader(getLongTrimmedTestResult())); while (true) { String line = reader.readLine(); if (line == null) break; // skip over frames that we won't be able to link to Matcher matcher = pattern.matcher(line); if (!line.contains("java.") && !line.contains("junit.") && !line.contains("\\s+sun\\.reflect") && !line.contains("edu.umd.cs.buildServer") && !line.contains("ReleaseTest") && !line.contains("PublicTest") && !line.contains("SecretTest") && !line.contains("SimpleTest") && !line.contains("TestAgainstFile") && !line.contains("SpiderTest") && matcher.find() && matcher.groupCount() > 1) { String sourceFileName = matcher.group(1); String lineNumber = matcher.group(2); return new FileNameLineNumberPair(sourceFileName, lineNumber); } } } catch (IOException ignore) { // cannot happen; reading from a String! } finally { IOUtils.closeQuietly(reader); } // XXX Does it make sense here to return a singleton representing nothing? return null; } else { throw new IllegalStateException( "You cannot get the filename and line number " + " of a test outcome of type " + getTestType()); } }
From source file:com.ikanow.infinit.e.harvest.enrichment.custom.UnstructuredAnalysisHarvester.java
/** * processHeader/* w w w. j a va2 s. co m*/ * * @param headerPattern * @param f * @param meta */ @SuppressWarnings("deprecation") private void processHeader(Pattern headerPattern, DocumentPojo f, List<metaField> meta, SourcePojo source, UnstructuredAnalysisConfigPojo uap) { if (headerPattern != null) { Matcher headerMatcher = headerPattern.matcher(f.getFullText()); String headerText = null; while (headerMatcher.find()) { if (headerMatcher.start() == 0) { headerText = headerMatcher.group(0); f.setHeaderEndIndex(headerText.length()); for (int i = 1; i < headerMatcher.groupCount() + 1; i++) { f.addToHeader(headerMatcher.group(i).trim()); } break; } } if (null != headerText && null != meta) { for (metaField m : meta) { if (m.context == Context.Header || m.context == Context.All) { this.processMeta(f, m, headerText, source, uap); } } } } }
From source file:com.ikanow.infinit.e.harvest.enrichment.custom.UnstructuredAnalysisHarvester.java
/** * processFooter//from w w w. ja v a2s . c o m * * @param footerPattern * @param f * @param meta */ @SuppressWarnings("deprecation") private void processFooter(Pattern footerPattern, DocumentPojo f, List<metaField> meta, SourcePojo source, UnstructuredAnalysisConfigPojo uap) { if (footerPattern != null) { Matcher footerMatcher = footerPattern.matcher(f.getFullText()); String footerText = null; while (footerMatcher.find()) { footerText = footerMatcher.group(0); int docLength = f.getFullText().length(); f.setFooterStartIndex(docLength - footerMatcher.group(0).length()); for (int i = 1; i < footerMatcher.groupCount() + 1; i++) { f.addToHeader(footerMatcher.group(i).trim()); } break; } if (null != footerText && null != meta) { for (metaField m : meta) { if (m.context == Context.Footer || m.context == Context.All) { this.processMeta(f, m, footerText, source, uap); } } } } }
From source file:org.apache.openaz.xacml.pdp.test.TestBase.java
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { ///* w w w . j a v a2 s . co m*/ // Sanity check the file name // Matcher matcher = this.pattern.matcher(file.getFileName().toString()); if (matcher.matches()) { // // if user has limited which files to use, check that here // if (testNumbersArray != null) { String fileNameString = file.getFileName().toString(); boolean found = false; for (String numberString : testNumbersArray) { if (fileNameString.contains(numberString)) { found = true; break; } } if (!found) { // // this test is not in the list to be run, so skip it // return super.visitFile(file, attrs); } } try { // // Pull what this request is supposed to be // String group = null; int count = matcher.groupCount(); if (count >= 1) { group = matcher.group(count - 1); } // // Send it // this.sendRequest(file, group); } catch (Exception e) { logger.error(e); e.printStackTrace(); } } return super.visitFile(file, attrs); }
From source file:com.zoffcc.applications.aagtl.HTMLDownloader.java
public String get_user_token() { String ret = ""; String url = "http://www.geocaching.com/map/default.aspx?lat=6&lng=9"; List<NameValuePair> values_list = new ArrayList<NameValuePair>(); String the_page = get_reader_stream(url, values_list, null, true); if (the_page == null) { if (CacheDownloader.DEBUG_) System.out.println("page = NULL"); return ""; }//from w ww.j a v a2 s.c o m String[] response_lines = the_page.split("\n"); String line = null; Pattern p = null; Matcher m = null; for (int i = 0; i < response_lines.length; i++) { line = response_lines[i]; // remove spaces at start and end of string line = line.trim(); if (line.startsWith("var uvtoken")) { if (CacheDownloader.DEBUG_) System.out.println("usertoken=" + line); p = Pattern.compile("userToken[ =]+'([^']+)'"); m = p.matcher(line); m.find(); if (m.groupCount() > 0) { if (CacheDownloader.DEBUG_) System.out.println("usertoken parsed=" + m.group(1)); return m.group(1); } } } // + for line in page: // // + if line.startswith('var uvtoken'): // // + self.user_token = // re.compile("userToken[ =]+'([^']+)'").search(line).group(1) // // + page.close() // // + return // // + raise // Exception("Website contents unexpected. Please check connection.") return ret; }
From source file:com.ephesoft.dcma.kvfieldcreation.KVFieldCreator.java
/** * This method gets the matched regex pattern for input string. * //from w ww . j a va 2s.c om * @param inputString * @param regexList * @return String */ private String getRegexPattern(String inputString, List<String> regexList) { String matchedPattern = null; int confidenceInt = 100; Pattern pattern = null; Matcher matcher = null; float previousMatchedConfidence = 0; if (null == inputString || inputString.isEmpty()) { LOGGER.info("Input string is null or empty."); } else { String dlfValue = inputString.split(KVFieldCreatorConstants.SPACE)[0]; for (String regex : regexList) { pattern = Pattern.compile(regex); matcher = pattern.matcher(dlfValue); while (matcher.find()) { for (int i = 0; i <= matcher.groupCount(); i++) { final String groupStr = matcher.group(i); if (null != groupStr) { final float confidence = (groupStr.length() * confidenceInt) / inputString.length(); if (confidence > previousMatchedConfidence) { previousMatchedConfidence = confidence; matchedPattern = regex; } } } } } if (matchedPattern == null) { LOGGER.info("No regex pattern found, setting input string as the regex itself. Pattern == " + inputString); matchedPattern = inputString; } } return matchedPattern; }
From source file:com.tao.realweb.util.StringUtil.java
/** * ??? // w ww . j av a 2 s. c om * * @param s * @param pf * @param pb * @param start * @return */ public static String stringReplace(String s, String pf, String pb, int start) { Pattern pattern_hand = Pattern.compile(pf); Matcher matcher_hand = pattern_hand.matcher(s); int gc = matcher_hand.groupCount(); int pos = start; String sf1 = ""; String sf2 = ""; String sf3 = ""; int if1 = 0; String strr = ""; while (matcher_hand.find(pos)) { sf1 = matcher_hand.group(); if1 = s.indexOf(sf1, pos); if (if1 >= pos) { strr += s.substring(pos, if1); pos = if1 + sf1.length(); sf2 = pb; for (int i = 1; i <= gc; i++) { sf3 = "\\" + i; sf2 = replaceAll(sf2, sf3, matcher_hand.group(i)); } strr += sf2; } else { return s; } } strr = s.substring(0, start) + strr; return strr; }
From source file:loci.formats.in.MetamorphReader.java
private Map.Entry<Integer, Integer> getWellCoords(String label) { Matcher matcher = WELL_COORDS.matcher(label); if (!matcher.find()) return null; int nGroups = matcher.groupCount(); if (nGroups != 2) return null; return new AbstractMap.SimpleEntry((int) (matcher.group(1).toUpperCase().charAt(0) - 'A'), Integer.parseInt(matcher.group(2)) - 1); }
From source file:com.boylesoftware.web.impl.AbstractRouterConfiguration.java
@Override public RouterRequest findRoute(final HttpServletRequest request, final HttpServletResponse response) throws MethodNotAllowedException, ServletException { // check if we have mappings if (this.mappings.length == 0) return null; // try to find the matching route mapping final Lock readLock = this.mappingsLock.readLock(); readLock.lock();/* w w w . j av a2 s. c om*/ try { // test request URI against the mappings RouteImpl mapping = this.mappings[0]; final String requestURI = request.getRequestURI(); // TODO: reusable matcher? final Matcher m = mapping.getURIPattern().matcher(requestURI); int mappingInd = 0; do { // try to match the mapping if (m.matches()) { // log the match if (this.log.isDebugEnabled()) this.log.debug("found mapping for URI " + requestURI + " on attempt " + (mappingInd + 1)); // move the mapping higher if matched more frequently final long numMatched = mapping.incrementNumMatched(); if (mappingInd > 0) { final RouteImpl prevMapping = this.mappings[mappingInd - 1]; if (numMatched > prevMapping.getNumMatched()) { final Lock writeLock = this.mappingsLock.writeLock(); readLock.unlock(); writeLock.lock(); try { this.mappings[mappingInd] = prevMapping; this.mappings[mappingInd - 1] = mapping; } finally { readLock.lock(); writeLock.unlock(); } } } // wrap the request final RouterRequestImpl routerRequest = this.routerRequestPool.getSync(); boolean success = false; try { // initialize the router request routerRequest.wrap(request, response, mapping, this.isAuthenticationRequired(requestURI)); // add parameters made from the URI components final int numURIParams = m.groupCount(); for (int i = 0; i < numURIParams; i++) { final String uriParamName = mapping.getURIParamName(i); if (uriParamName != null) routerRequest.addParameter(uriParamName, m.group(i + 1)); } // convert flash attributes cookie to request attributes routerRequest.flashCookieToAttributes(); // return the router request success = true; return routerRequest; } finally { if (!success) routerRequest.recycle(); } } // next mapping for next iteration if (++mappingInd >= this.mappings.length) break; mapping = this.mappings[mappingInd]; // reuse the matcher m.reset(); m.usePattern(mapping.getURIPattern()); } while (true); } finally { readLock.unlock(); } // no mapping matched return null; }
From source file:logdruid.ui.table.StatRecordingEditorTable.java
public void FixValues() { String patternString = ""; Matcher matcher; PatternCache patternCache = new PatternCache(); Iterator it = data.iterator(); Object[] obj;//from w ww . ja v a 2 s . c om while (it.hasNext()) { obj = (Object[]) it.next(); String stBefore = (String) obj[1]; String stType = (String) obj[2]; String stAfter = (String) obj[3]; logger.info("stType: " + stType); if (stType.equals("date") && rep.getDateFormat(recording.getDateFormatID()).getPattern() != null) { patternString += stBefore + "(" + rep.getDateFormat(recording.getDateFormatID()).getPattern() + ")" + stAfter; logger.info("getTypeString(stType) getPattern -: " + rep.getDateFormat(recording.getDateFormatID()).getPattern()); logger.info("getTypeString(stType) getDateFormat -: " + rep.getDateFormat(recording.getDateFormatID()).getDateFormat()); } else { patternString += stBefore + "(" + DataMiner.getTypeString(stType) + ")" + stAfter; logger.info("getTypeString(stType) -: " + DataMiner.getTypeString(stType)); } } try { logger.info("theLine: " + examplePane.getText()); logger.info("patternString: " + patternString); Highlighter h = examplePane.getHighlighter(); h.removeAllHighlights(); int currIndex = 0; String[] lines = examplePane.getText().split(System.getProperty("line.separator")); if (lines.length >= 1) { for (int i = 0; i < lines.length; i++) { matcher = patternCache.getPattern(patternString).matcher(lines[i]); if (matcher.find()) { // int currIndex = 0; // doc.insertString(doc.getLength(),line+"\n", null); for (int i2 = 1; i2 <= matcher.groupCount(); i2++) { model.setValueAt(matcher.group(i2), i2 - 1, 5); h.addHighlight(currIndex + matcher.start(i2), +currIndex + matcher.end(i2), new DefaultHighlighter.DefaultHighlightPainter(Color.ORANGE)); } } currIndex += lines[i].length() + 1; } } } catch (Exception e1) { e1.printStackTrace(); // System.exit(1); } }