/**
* A utility method that is useful for stripping a list of words from all the fields of the
* RevisionMetadata.
*
* @param rm the RevisionMetadata to scrub
* @param words the list of words to replace
* @param replacement the String to replace the target words with
* @param wordAlone true if the words to match must surrounded by word boundaries
* @return a copy representing the RevisionMetadata resulting from the scrub
*/
public static RevisionMetadata stripFromAllFields(
RevisionMetadata rm, List<String> words, String replacement, boolean wordAlone) {
String newId = rm.id();
String newAuthor = rm.author();
String newDescription = rm.description();
ListMultimap<String, String> newFields = LinkedListMultimap.create(rm.fields());
for (String word : words) {
String regex = (wordAlone) ? ("(?i)(\\b)" + word + "(\\b)") : ("(?i)" + word);
newId = newId.replaceAll(regex, replacement);
newAuthor = newAuthor.replaceAll(regex, replacement);
newDescription = newDescription.replaceAll(regex, replacement);
for (Entry<String, String> entry : newFields.entries()) {
entry.setValue(entry.getValue().replaceAll(regex, replacement));
}
}
return rm.toBuilder()
.id(newId)
.author(newAuthor)
.description(newDescription)
.replacingFieldsWith(ImmutableSetMultimap.copyOf(newFields))
.build();
}
MetadataScrubber.java 文件源码
java
阅读 26
收藏 0
点赞 0
评论 0
项目:MOE
作者:
评论列表
文章目录