本文整理汇总了Java中com.google.re2j.Pattern类的典型用法代码示例。如果您正苦于以下问题:Java Pattern类的具体用法?Java Pattern怎么用?Java Pattern使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Pattern类属于com.google.re2j包,在下文中一共展示了Pattern类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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();
}
示例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");
}
示例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");
}
示例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");
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
}
示例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;
}
示例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"));
}