List of usage examples for java.util.regex Matcher reset
public Matcher reset(CharSequence input)
From source file:com.cyberway.issue.crawler.extractor.ExtractorURI.java
/** * Look for URIs inside the supplied UURI. * /*from w w w . j a v a2 s.c o m*/ * Static for ease of testing or outside use. * * @param source UURI to example * @return List of discovered String URIs. */ protected static List<String> extractQueryStringLinks(UURI source) { List<String> results = new ArrayList<String>(); String decodedQuery; try { decodedQuery = source.getQuery(); } catch (URIException e1) { // shouldn't happen return results; } if (decodedQuery == null) { return results; } // check if full query-string appears to be http(s) URI Matcher m = TextUtils.getMatcher(ABS_HTTP_URI_PATTERN, decodedQuery); if (m.matches()) { TextUtils.recycleMatcher(m); results.add(decodedQuery); } // split into params, see if any param value is http(s) URI String rawQuery = new String(source.getRawQuery()); String[] params = rawQuery.split("&"); for (String param : params) { String[] keyVal = param.split("="); if (keyVal.length == 2) { String candidate; try { candidate = LaxURLCodec.DEFAULT.decode(keyVal[1]); } catch (DecoderException e) { continue; } // TODO: use other non-UTF8 codecs when appropriate m.reset(candidate); if (m.matches()) { results.add(candidate); } } } return results; }
From source file:org.apache.accumulo.server.logger.LogReader.java
public static void printLogEvent(LogFileKey key, LogFileValue value, Text row, Matcher rowMatcher, KeyExtent ke, Set<Integer> tabletIds, int maxMutations) { if (ke != null) { if (key.event == LogEvents.DEFINE_TABLET) { if (key.tablet.equals(ke)) { tabletIds.add(key.tid);//www .ja v a 2s. c o m } else { return; } } else if (!tabletIds.contains(key.tid)) { return; } } if (row != null || rowMatcher != null) { if (key.event == LogEvents.MUTATION || key.event == LogEvents.MANY_MUTATIONS) { boolean found = false; for (Mutation m : value.mutations) { if (row != null && new Text(m.getRow()).equals(row)) { found = true; break; } if (rowMatcher != null) { rowMatcher.reset(new String(m.getRow())); if (rowMatcher.matches()) { found = true; break; } } } if (!found) return; } else { return; } } System.out.println(key); System.out.println(LogFileValue.format(value, maxMutations)); }
From source file:br.bireme.ngrams.NGrams.java
private static int compareRegExpFields(final br.bireme.ngrams.Field field, final String fld, final Document doc) { assert field != null; assert doc != null; final int ret; final String text = (String) doc.get(field.name); final String xfld = (fld == null) ? "" : fld.trim(); final String xtext = (text == null) ? "" : text.trim(); if (xfld.isEmpty() && xtext.isEmpty()) { ret = -1;// w ww. j ava 2s.c om } else { final RegExpField regExp = (RegExpField) field; final Matcher mat = regExp.matcher; mat.reset(xtext); if (mat.find()) { final String content1 = mat.group(regExp.groupNum); if (content1 == null) { ret = compareFields(field, xfld, xtext); } else { mat.reset(xfld); if (mat.find()) { final String content2 = mat.group(regExp.groupNum); if (content2 == null) { ret = compareFields(field, xfld, xtext); } else { ret = compareFields(field, content1, content2); } } else { ret = compareFields(field, xfld, xtext); } } } else { ret = compareFields(field, xfld, xtext); } } return ret; }
From source file:com.carmatech.maven.MergeOperation.java
private boolean isVariable(final Object value, final Matcher matcher) { return (value != null) && (matcher.reset(value.toString()).matches()); }
From source file:cz.muni.fi.mir.db.service.impl.AnnotationValueSerivceImpl.java
@Override public void populate() { List<Annotation> annotations = annotationDAO.getAllAnnotations(); Set<String> annotationsValues = new HashSet<>(); Matcher m = pattern.matcher(""); for (Annotation a : annotations) { m.reset(a.getAnnotationContent()); while (m.find()) { annotationsValues.add(m.group()); }//from w w w . j a v a 2s .c om } for (String s : annotationsValues) { AnnotationValue av = annotationValueDAO.getByValue(s); if (av == null) { av = new AnnotationValue(); av.setValue(s); annotationValueDAO.create(av); } } }
From source file:org.apache.hadoop.hive.conf.SystemVariables.java
protected final String substitute(Configuration conf, String expr, int depth) { Matcher match = varPat.matcher(""); String eval = expr;/* w w w . ja v a2s . c om*/ StringBuilder builder = new StringBuilder(); int s = 0; for (; s <= depth; s++) { match.reset(eval); builder.setLength(0); int prev = 0; boolean found = false; while (match.find(prev)) { String group = match.group(); String var = group.substring(2, group.length() - 1); // remove ${ .. } String substitute = getSubstitute(conf, var); if (substitute == null) { substitute = group; // append as-is } else { found = true; } builder.append(eval.substring(prev, match.start())).append(substitute); prev = match.end(); } if (!found) { return eval; } builder.append(eval.substring(prev)); eval = builder.toString(); } if (s > depth) { throw new IllegalStateException( "Variable substitution depth is deeper than " + depth + " for expression " + expr); } return eval; }
From source file:rs.pedjaapps.kerneltuner.utility.IOHelper.java
private static Matcher resetMatcher(Matcher matcher, String input, Pattern pattern) { if (matcher == null) return pattern.matcher(input); else//from www . j a v a 2 s .c o m return matcher.reset(input); }
From source file:org.structr.rest.resource.ViewFilterResource.java
@Override public String getResourceSignature() { StringBuilder signature = new StringBuilder(); String signaturePart = wrappedResource.getResourceSignature(); if (signaturePart.contains("/")) { String[] parts = StringUtils.split(signaturePart, "/"); Matcher matcher = uuidPattern.matcher(""); for (String subPart : parts) { // re-use pattern matcher for better performance matcher.reset(subPart); if (!matcher.matches()) { signature.append(subPart); signature.append("/"); }//from ww w .jav a 2 s . c o m } } else { signature.append(signaturePart); } if (propertyView != null) { // append view / scope part if (!signature.toString().endsWith("/")) { signature.append("/"); } signature.append("_"); signature.append(SchemaHelper.normalizeEntityName(propertyView)); } return StringUtils.stripEnd(signature.toString(), "/"); }
From source file:org.sonar.cxx.sensors.coverage.TestwellCtcTxtParser.java
/** * {@inheritDoc}// ww w.j a va 2 s . co m */ @Override public void processReport(final SensorContext context, File report, final Map<String, CoverageMeasures> coverageData) { LOG.debug("Parsing 'Testwell CTC++' textual format"); try (Scanner s = new Scanner(report).useDelimiter(SECTION_SEP)) { scanner = s; Matcher headerMatcher = FILE_HEADER.matcher(scanner.next()); while (parseUnit(coverageData, headerMatcher)) { headerMatcher.reset(scanner.next()); } } catch (FileNotFoundException e) { LOG.warn("File not found '{}'", e.getMessage()); } catch (NoSuchElementException e) { LOG.debug("File section not found."); } }
From source file:esg.node.components.registry.RegistrationGleanerHelperDAO.java
public void init() { attributeGroupsResultSetHandler = new ResultSetHandler<Map<String, String>>() { public Map<String, String> handle(ResultSet rs) throws SQLException { HashMap<String, String> results = new HashMap<String, String>(); String name = null;// w w w.j av a2s . c om String desc = null; java.util.regex.Matcher typeMatcher = AtsWhitelistGleaner.TYPE_PATTERN.matcher(""); while (rs.next()) { name = rs.getString(1); desc = rs.getString(2); typeMatcher.reset(name); if (typeMatcher.find()) { log.trace("Skipping " + name); continue; } results.put(name, desc); } return results; } }; }