下面列出了com.google.common.collect.ListMultimap#entries ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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 = replaceAuthor(newAuthor, word, 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)
.fields(ImmutableSetMultimap.copyOf(newFields))
.build();
}
/**
* This method is the same to {@link #createLinkHeader(Page, String, Map, Object...)} except of
* receiving multivalued query parameters.
*/
protected String createLinkHeader(
Page<?> page, String method, ListMultimap<String, Object> queryParams, Object... pathParams) {
final UriBuilder ub = getServiceContext().getServiceUriBuilder().path(getClass(), method);
for (Map.Entry<String, Object> queryParam : queryParams.entries()) {
ub.queryParam(queryParam.getKey(), queryParam.getValue());
}
return PagingUtil.createLinkHeader(page, ub.build(pathParams));
}
@Override
public Iterable<String[]> dump(int mode) {
List<String[]> list = new LinkedList<String[]>();
List<Integer> ids = new ArrayList<Integer>();
ids.addAll(EntityList.IDtoClassMapping.keySet());
Collections.sort(ids);
for (int id : ids) {
list.add(new String[] { GLOBAL, String.valueOf(id), EntityList.getStringFromID(id), EntityList.getClassFromID(id).getName() });
}
ListMultimap<ModContainer, EntityRegistration> modEntities = ReflectionHelper.getPrivateValue(EntityRegistry.class, EntityRegistry.instance(), "entityRegistrations");
for (Entry<ModContainer, EntityRegistration> e : modEntities.entries()) {
EntityRegistration er = e.getValue();
list.add(new String[] { e.getKey().getModId(), String.valueOf(er.getModEntityId()), e.getKey().getModId() + "." + er.getEntityName(), er.getEntityClass().getName() });
}
Collections.sort(list, new Comparator<String[]>() {
@Override
public int compare(String[] s1, String[] s2) {
if (s1[0].equals(GLOBAL) && !s1[0].equals(s2[0])) {
return -1;
}
int i = s1[0].compareTo(s2[0]);
if (i != 0) {
return i;
}
return Integer.compare(Integer.valueOf(s1[1]), Integer.valueOf(s2[1]));
}
});
return list;
}