• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Pattern类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.re2j.Pattern的典型用法代码示例。如果您正苦于以下问题:Java Pattern类的具体用法?Java Pattern怎么用?Java Pattern使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Pattern类属于com.google.re2j包,在下文中一共展示了Pattern类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: trimClassGraph

import com.google.re2j.Pattern; //导入依赖的package包/类
/** Removes all outgoing edges from classes that are not white listed. */
private static ImmutableGraph<String> trimClassGraph(
    ImmutableGraph<String> classGraph, Pattern whiteList, Pattern blackList) {
  MutableGraph<String> graph = GraphBuilder.directed().allowsSelfLoops(false).build();
  for (String src : classGraph.nodes()) {
    if (!whiteList.matcher(src).find() || blackList.matcher(src).find()) {
      continue;
    }
    graph.addNode(src);
    for (String dst : classGraph.successors(src)) {
      if (blackList.matcher(dst).find()) {
        continue;
      }
      graph.putEdge(src, dst);
    }
  }
  return ImmutableGraph.copyOf(graph);
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:19,代码来源:ClassGraphPreprocessor.java


示例2: noMatchingClassNames

import com.google.re2j.Pattern; //导入依赖的package包/类
/**
 * Tests behavior of resolver when there are no classes that match white list pattern. The
 * resulting map should contain no entries.
 */
@Test
public void noMatchingClassNames() throws IOException {
  MutableGraph<String> classgraph = newGraph(String.class);
  classgraph.putEdge("com.A", "com.B");
  classgraph.putEdge("com.B", "com.C");

  ProjectClassToRuleResolver resolver =
      newResolver(
          classgraph,
          Pattern.compile("com.hello.*"),
          ImmutableMap.of(
              "com.A",
              workspace.resolve("java/com/A.java"),
              "com.B",
              workspace.resolve("java/com/B.java"),
              "com.C",
              workspace.resolve("java/com/C.java")));

  ImmutableMap<String, BuildRule> actual = resolver.resolve(classgraph.nodes());
  assertThat(actual).isEmpty();
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:26,代码来源:ProjectClassToRuleResolverTest.java


示例3: trimRemovesBlackListedClasses

import com.google.re2j.Pattern; //导入依赖的package包/类
/** Tests whether the black listed class names are removed from the class graph. */
@Test
public void trimRemovesBlackListedClasses() {
  MutableGraph<String> graph = newGraph();
  graph.putEdge("com.BlackList", "com.WhiteList");
  graph.putEdge("com.WhiteList", "com.BlackList");

  Pattern blackList = Pattern.compile("BlackList");

  Graph<String> actual =
      preProcessClassGraph(ImmutableGraph.copyOf(graph), EVERYTHING, blackList);

  MutableGraph<String> expected = newGraph();
  expected.addNode("com.WhiteList");

  assertEquivalent(actual, expected);
  assertThat(actual.nodes()).doesNotContain("com.BlackList");
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:19,代码来源:ClassGraphPreprocessorTest.java


示例4: trimRemovesTransitiveDependenciesToNonWhiteListedClasses

import com.google.re2j.Pattern; //导入依赖的package包/类
/**
 * Asserts that the only nodes in the trimmed graph are white listed classes and classes that the
 * white listed classes are directly dependent on.
 */
@Test
public void trimRemovesTransitiveDependenciesToNonWhiteListedClasses() {
  MutableGraph<String> graph = newGraph();
  graph.putEdge("com.WhiteList", "com.OtherList");
  graph.putEdge("com.OtherList", "com.TransitiveDependency");

  Pattern whiteList = Pattern.compile("WhiteList");

  Graph<String> actual = preProcessClassGraph(ImmutableGraph.copyOf(graph), whiteList, NOTHING);

  MutableGraph<String> expected = newGraph();
  expected.putEdge("com.WhiteList", "com.OtherList");

  assertEquivalent(actual, expected);
  assertThat(actual.nodes()).doesNotContain("com.TransitiveDependency");
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:21,代码来源:ClassGraphPreprocessorTest.java


示例5: trimRemovesTransitiveDepsOfBlackListedClasses

import com.google.re2j.Pattern; //导入依赖的package包/类
/**
 * Tests whether black listed classes names as well as their non-whitelisted dependencies are
 * removed from the class graph. In addition to not containing the black listed class, the
 * resulting graph should also not contain nonwhite listed classes only black listed classes are
 * dependent on. For example, say we were to have the following class graph
 *
 * <p>com.Whitelist --> com.Blacklist --> com.NonWhitelist
 *
 * <p>Then the resulting class graph should only contain com.Whitelist
 */
@Test
public void trimRemovesTransitiveDepsOfBlackListedClasses() {
  MutableGraph<String> graph = newGraph();
  graph.putEdge("com.BlackList", "com.OtherList");
  graph.putEdge("com.WhiteList", "com.BlackList");

  Pattern blackList = Pattern.compile("BlackList");
  Pattern whiteList = Pattern.compile("WhiteList");

  Graph<String> actual = preProcessClassGraph(ImmutableGraph.copyOf(graph), whiteList, blackList);

  MutableGraph<String> expected = newGraph();
  expected.addNode("com.WhiteList");

  assertEquivalent(actual, expected);
  assertThat(actual.nodes()).doesNotContain("com.BlackList");
  assertThat(actual.nodes()).doesNotContain("com.OtherList");
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:29,代码来源:ClassGraphPreprocessorTest.java


示例6: accepts

import com.google.re2j.Pattern; //导入依赖的package包/类
@Override
public boolean accepts(MetricsTag tag) {
  // Accept if whitelisted
  Pattern ipat = includeTagPatterns.get(tag.name());
  if (ipat != null && ipat.matcher(tag.value()).matches()) {
    return true;
  }
  // Reject if blacklisted
  Pattern epat = excludeTagPatterns.get(tag.name());
  if (epat != null && epat.matcher(tag.value()).matches()) {
    return false;
  }
  // Reject if no match in whitelist only mode
  if (!includeTagPatterns.isEmpty() && excludeTagPatterns.isEmpty()) {
    return false;
  }
  return true;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:19,代码来源:AbstractPatternFilter.java


示例7: Replace

import com.google.re2j.Pattern; //导入依赖的package包/类
private Replace(TemplateTokens before, TemplateTokens after,
    Map<String, Pattern> regexGroups, boolean firstOnly, boolean multiline,
    boolean repeatedGroups,
    Glob fileMatcherBuilder,
    List<Pattern> patternsToIgnore,
    WorkflowOptions workflowOptions) {
  this.before = Preconditions.checkNotNull(before);
  this.after = Preconditions.checkNotNull(after);
  this.regexGroups = ImmutableMap.copyOf(regexGroups);
  this.firstOnly = firstOnly;
  this.multiline = multiline;
  this.repeatedGroups = repeatedGroups;
  this.fileMatcherBuilder = Preconditions.checkNotNull(fileMatcherBuilder);
  this.patternsToIgnore = ImmutableList.copyOf(patternsToIgnore);
  this.workflowOptions = Preconditions.checkNotNull(workflowOptions);
}
 
开发者ID:google,项目名称:copybara,代码行数:17,代码来源:Replace.java


示例8: create

import com.google.re2j.Pattern; //导入依赖的package包/类
public static ReferenceMigrator create(
    String before, String after, Pattern forward, @Nullable Pattern backward,
    ImmutableList<String> additionalLabels, Location location) throws EvalException {
  Map<String, Pattern> patterns = ImmutableMap.of("reference", forward);
  TemplateTokens beforeTokens =
      new TemplateTokens(location, before, patterns, /* repeatedGroups= */ false);
  beforeTokens.validateUnused();
  TemplateTokens afterTokens =
      new TemplateTokens(location, after, patterns, /* repeatedGroups= */ false);
  afterTokens.validateUnused();
  if (after.lastIndexOf("$1") != -1) {
    // TODO: Handle escaping
    throw new EvalException(location,
        String.format("Destination format '%s' uses the reserved token '$1'.", after));
  }
  return new ReferenceMigrator(beforeTokens, afterTokens, backward, additionalLabels);
}
 
开发者ID:google,项目名称:copybara,代码行数:18,代码来源:ReferenceMigrator.java


示例9: run

import com.google.re2j.Pattern; //导入依赖的package包/类
private Set<FileState> run(Iterable<FileState> files, Console console) throws IOException, ValidationException {
  Set<FileState> modifiedFiles = new HashSet<>();
  // TODO(malcon): Remove reconstructing pattern once RE2J doesn't synchronize on matching.
  Pattern batchPattern = Pattern.compile(pattern.pattern(), pattern.flags());
  for (FileState file : files) {
    if (Files.isSymbolicLink(file.getPath())) {
      continue;
    }
    String content = new String(Files.readAllBytes(file.getPath()), UTF_8);
    Matcher matcher = batchPattern.matcher(content);
    StringBuffer sb = new StringBuffer();
    boolean modified = false;
    while (matcher.find()) {
      List<String> users = Splitter.on(",").splitToList(matcher.group(2));
      List<String> mappedUsers = mapUsers(users, matcher.group(0), file.getPath(), console);
      modified |= !users.equals(mappedUsers);
      String result = matcher.group(1);
      if (!mappedUsers.isEmpty()) {
        result += "(" + Joiner.on(",").join(mappedUsers) + ")";
      }
      matcher.appendReplacement(sb, result);
    }
    matcher.appendTail(sb);

    if (modified) {
      modifiedFiles.add(file);
      Files.write(file.getPath(), sb.toString().getBytes(UTF_8));
    }
  }
  return modifiedFiles;
}
 
开发者ID:google,项目名称:copybara,代码行数:32,代码来源:TodoReplace.java


示例10: Replacer

import com.google.re2j.Pattern; //导入依赖的package包/类
private Replacer(Pattern before, TemplateTokens after, AlterAfterTemplate callback,
    boolean firstOnly, boolean multiline,
    @Nullable List<Pattern> patternsToIgnore) {
  this.before = before;
  this.after = after;
  afterReplaceTemplate = this.after.after(TemplateTokens.this);
  // Precomputed the repeated groups as this should be used only on rare occasions and we
  // don't want to iterate over the map for every line.
  for (Entry<String, Collection<Integer>> e : groupIndexes.asMap().entrySet()) {
    if (e.getValue().size() > 1) {
      repeatedGroups.putAll(e.getKey(), e.getValue());
    }
  }
  this.firstOnly = firstOnly;
  this.multiline = multiline;
  this.callback = callback;
  this.patternsToIgnore = patternsToIgnore;
}
 
开发者ID:google,项目名称:copybara,代码行数:19,代码来源:TemplateTokens.java


示例11: setUp

import com.google.re2j.Pattern; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  FileSystem fs = Jimfs.newFileSystem();
  checkoutDir = fs.getPath("/test-checkoutDir");
  origin = new DummyOrigin();
  destinationReader = new MockReader();
  location = new Location(1, 2) {
    @Override
    public PathFragment getPath() {
      return null;
    }
  };
  referenceMigrator = ReferenceMigrator.create(
      "http://internalReviews.com/${reference}",
      "http://externalreviews.com/view?${reference}",
      Pattern.compile("[0-9]+"),
      Pattern.compile("[0-9a-f]+"),
      ImmutableList.of(),
      location);
  OptionsBuilder options = new OptionsBuilder();
  console = new TestingConsole();
  options.setConsole(console);
  skylark = new SkylarkTestExecutor(options, MetadataModule.class);

}
 
开发者ID:google,项目名称:copybara,代码行数:26,代码来源:RevisionMigratorTest.java


示例12: extractIDString

import com.google.re2j.Pattern; //导入依赖的package包/类
/**
 * Extract Date + ID + No
 * Ex: " 15/02/14(六)07:14:32 ID:F.OqpZFA No.6135732"
 * @return Post
 */
private Post extractIDString(Post post, TextNode node) {
    Pattern r = Pattern.compile("(\\d{2})/(\\d{2})/(\\d{2}).+?(\\d{2}):(\\d{2}):(\\d{2}) ID:([\\./0-9A-Za-z]+?) No\\.(\\d+)");
    Matcher m = r.matcher(node.text());
    if (m.find()) {
        Integer Y = Integer.parseInt(m.group(1)) + 2000, //year
                M = Integer.parseInt(m.group(2)) - 1, //month
                D = Integer.parseInt(m.group(3)), //day
                H = Integer.parseInt(m.group(4)), //hours
                I = Integer.parseInt(m.group(5)), //minutes
                S = Integer.parseInt(m.group(6)); //seconds
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Asia/Taipei"));
        cal.set(Y, M, D, H, I, S);
        post.date = cal;

        post.tripId = m.group(7);
        post.no = m.group(8);
    }

    return post;
}
 
开发者ID:touhonoob,项目名称:KomiReader,代码行数:26,代码来源:KomicaScraper.java


示例13: compilePattern

import com.google.re2j.Pattern; //导入依赖的package包/类
private static Pattern compilePattern(CmdLineParser cmdLineParser, String patternString) {
  try {
    return Pattern.compile(patternString);
  } catch (IllegalArgumentException e) {
    explainUsageErrorAndExit(cmdLineParser, String.format("Invalid regex: %s", e.getMessage()));
    return null;
  }
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:9,代码来源:Bfg.java


示例14: ProjectClassToRuleResolver

import com.google.re2j.Pattern; //导入依赖的package包/类
ProjectClassToRuleResolver(
    ImmutableGraph<String> classGraph,
    Pattern whiteList,
    ImmutableMap<String, Path> classToFile,
    Path workspace) {
  checkNoInnerClassesPresent(classGraph.nodes());
  this.classToFile = classToFile;
  this.workspace = workspace;
  this.classGraph = classGraph;
  this.whiteList = whiteList;
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:12,代码来源:ProjectClassToRuleResolver.java


示例15: testSingleMatch

import com.google.re2j.Pattern; //导入依赖的package包/类
@Test
public void testSingleMatch() {
  List<ReFieldConfig> fields = new ArrayList<>();
  fields.add(new ReFieldConfig("foo", ReFieldType.STRING));

  Pattern p = Pattern.compile("(.*)");
  Re2jRegexDeserializer deser = new Re2jRegexDeserializer(p, fields);
  DeserializedEvent event = deser.deserialize("test i am");

  assertEquals("test i am", event.getField("foo"));
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:12,代码来源:Re2jRegexDeserializerTest.java


示例16: testNoMatches

import com.google.re2j.Pattern; //导入依赖的package包/类
@Test(expected = DeserializationException.class)
public void testNoMatches() {
  List<ReFieldConfig> fields = new ArrayList<>();
  fields.add(new ReFieldConfig("foo", ReFieldType.STRING));

  Pattern p = Pattern.compile("(test i am)");
  Re2jRegexDeserializer deser = new Re2jRegexDeserializer(p, fields);
  DeserializedEvent event = deser.deserialize("i am a test");
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:10,代码来源:Re2jRegexDeserializerTest.java


示例17: VerifyMatch

import com.google.re2j.Pattern; //导入依赖的package包/类
private VerifyMatch(Pattern pattern, boolean verifyNoMatch, Glob fileMatcherBuilder,
    LocalParallelizer parallelizer) {
  this.pattern = Preconditions.checkNotNull(pattern);
  this.verifyNoMatch = verifyNoMatch;
  this.fileMatcherBuilder = Preconditions.checkNotNull(fileMatcherBuilder);
  this.parallelizer = parallelizer;
}
 
开发者ID:google,项目名称:copybara,代码行数:8,代码来源:VerifyMatch.java


示例18: run

import com.google.re2j.Pattern; //导入依赖的package包/类
@Override
public List<String> run(Iterable<FileState> files)
    throws IOException, ValidationException {
  List<String> errors = new ArrayList<>();
  // TODO(malcon): Remove reconstructing pattern once RE2J doesn't synchronize on matching.
  Pattern batchPattern = Pattern.compile(pattern.pattern(), pattern.flags());
  for (FileState file : files) {
    String originalFileContent = new String(Files.readAllBytes(file.getPath()), UTF_8);
    if (verifyNoMatch == batchPattern.matcher(originalFileContent).find()) {
      errors.add(checkoutDir.relativize(file.getPath()).toString());
    }
  }
  return errors;
}
 
开发者ID:google,项目名称:copybara,代码行数:15,代码来源:VerifyMatch.java


示例19: create

import com.google.re2j.Pattern; //导入依赖的package包/类
public static VerifyMatch create(Location location, String regEx, Glob paths,
    boolean verifyNoMatch, LocalParallelizer parallelizer) throws EvalException {
  Pattern parsed;
  try {
    parsed = Pattern.compile(regEx, Pattern.MULTILINE);
  } catch (PatternSyntaxException e) {
    throw new EvalException(location, String.format("Regex '%s' is invalid.", regEx), e);
  }
  return new VerifyMatch(parsed, verifyNoMatch, paths, parallelizer);
}
 
开发者ID:google,项目名称:copybara,代码行数:11,代码来源:VerifyMatch.java


示例20: BatchReplace

import com.google.re2j.Pattern; //导入依赖的package包/类
BatchReplace(TemplateTokens before, TemplateTokens after, boolean firstOnly,
    boolean multiline, ImmutableList<Pattern> patternsToIgnore) {
  this.before = before;
  this.after = after;
  this.firstOnly = firstOnly;
  this.multiline = multiline;
  this.patternsToIgnore = patternsToIgnore;
}
 
开发者ID:google,项目名称:copybara,代码行数:9,代码来源:Replace.java



注:本文中的com.google.re2j.Pattern类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MarkupTemplateEngine类代码示例发布时间:2022-05-22
下一篇:
Java Calls类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap