本文整理匯總了Java中com.google.common.collect.Multimaps.newMultimap方法的典型用法代碼示例。如果您正苦於以下問題:Java Multimaps.newMultimap方法的具體用法?Java Multimaps.newMultimap怎麽用?Java Multimaps.newMultimap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.collect.Multimaps
的用法示例。
在下文中一共展示了Multimaps.newMultimap方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: groupByURI
import com.google.common.collect.Multimaps; //導入方法依賴的package包/類
protected Multimap<URI, MWEDiagnostic> groupByURI(MWEDiagnostic[] diagnostic) {
Multimap<URI, MWEDiagnostic> result = Multimaps.newMultimap(
Maps.<URI, Collection<MWEDiagnostic>> newLinkedHashMap(), new Supplier<Collection<MWEDiagnostic>>() {
@Override
public Collection<MWEDiagnostic> get() {
return Sets.newTreeSet(getDiagnosticComparator());
}
});
result.putAll(Multimaps.index(Arrays.asList(diagnostic), new Function<MWEDiagnostic, URI>() {
@Override
public URI apply(MWEDiagnostic from) {
Issue issue = (Issue) from.getElement();
URI uriToProblem = issue.getUriToProblem();
return uriToProblem != null ? uriToProblem.trimFragment() : NullURI;
}
}));
return result;
}
示例2: getDuplicates
import com.google.common.collect.Multimaps; //導入方法依賴的package包/類
/**
* Gets duplicates of a given type based on a guard (predicate). A given function is used for converting an instance of type T
* to a string which is used for checking for duplicates.
*
* @param <T>
* the generic type
* @param predicate
* the predicate acting as a guard
* @param function
* returns a string for an instance of type T
* @param elements
* the elements to be checked
* @return the duplicates
*/
private <T extends EObject> Iterable<T> getDuplicates(final Predicate<T> predicate, final Function<T, String> function, final Iterable<T> elements) {
List<T> result = Lists.newArrayList();
Multimap<String, T> multiMap = Multimaps.newMultimap(Maps.<String, Collection<T>> newHashMap(), new Supplier<Collection<T>>() {
@Override
public Collection<T> get() {
return Lists.<T> newArrayList();
}
});
for (final T candidate : elements) {
if (predicate.apply(candidate)) {
multiMap.put(function.apply(candidate), candidate);
}
}
for (String elem : multiMap.keySet()) {
final Collection<T> duplicates = multiMap.get(elem);
if (duplicates.size() > 1) {
result.addAll(duplicates);
}
}
return result;
}
示例3: checkContextTypeIsUnique
import com.google.common.collect.Multimaps; //導入方法依賴的package包/類
/**
* Checks that a check's context types are all unique.
*
* @param check
* the check
*/
// TODO there is no reason for a context type to be unique, except that we are too lazy to generate the right code, right?
@Check
public void checkContextTypeIsUnique(final com.avaloq.tools.ddk.check.check.Check check) {
if (check.getContexts().size() < 1) {
return;
}
Multimap<String, Context> mm = Multimaps.newMultimap(Maps.<String, Collection<Context>> newHashMap(), new Supplier<Collection<Context>>() {
@Override
public Collection<Context> get() {
return Lists.newArrayList();
}
});
for (final Context c : check.getContexts()) {
final ContextVariable var = c.getContextVariable();
if (var != null) {
final JvmTypeReference contextType = var.getType();
if (contextType != null && contextType.getType() != null && !contextType.getType().eIsProxy()) {
mm.put(contextType.getType().getIdentifier(), c);
}
}
}
for (String type : mm.keys()) {
final Collection<Context> duplicatesForType = mm.get(type);
if (duplicatesForType.size() > 1) {
for (final Context duplicateContext : duplicatesForType) {
error(Messages.CheckJavaValidator_CONTEXT_TYPES_UNIQUE, duplicateContext.getContextVariable(), //
CheckPackage.Literals.CONTEXT_VARIABLE__TYPE, IssueCodes.CONTEXT_TYPES_NOT_UNIQUE);
}
}
}
}
示例4: createReferenceCountingMultimap
import com.google.common.collect.Multimaps; //導入方法依賴的package包/類
private <K, V> Multimap<K, V> createReferenceCountingMultimap() {
return Multimaps.newMultimap(new HashMap<K, Collection<V>>(), new Supplier<Multiset<V>>() {
@Override
public Multiset<V> get() {
return HashMultiset.create();
}
});
}
示例5: deserialize
import com.google.common.collect.Multimaps; //導入方法依賴的package包/類
@Override
public Multimap<?, ?> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
final Multimap<String, String> map = Multimaps.newMultimap(new HashMap<String, Collection<String>>(), new Supplier<Set<String>>() {
public Set<String> get() {
return Sets.newHashSet();
}
});
for (Map.Entry<String, JsonElement> entry : ((JsonObject) json).entrySet()) {
for (JsonElement element : (JsonArray) entry.getValue()) {
map.get(entry.getKey()).add(element.getAsString());
}
}
return map;
}
示例6: ModLoaderClientHelper
import com.google.common.collect.Multimaps; //導入方法依賴的package包/類
public ModLoaderClientHelper(Minecraft client)
{
this.client = client;
ModLoaderHelper.sidedHelper = this;
keyBindingContainers = Multimaps.newMultimap(Maps.<ModLoaderModContainer, Collection<ModLoaderKeyBindingHandler>>newHashMap(), new Supplier<Collection<ModLoaderKeyBindingHandler>>()
{
@Override
public Collection<ModLoaderKeyBindingHandler> get()
{
return Collections.singleton(new ModLoaderKeyBindingHandler());
}
});
}
示例7: newEnumMultimap
import com.google.common.collect.Multimaps; //導入方法依賴的package包/類
public static <K extends Enum<K>, V> Multimap<K, V> newEnumMultimap(Class<K> keyType, Supplier<? extends Collection<V>> factory) {
return Multimaps.newMultimap(Maps.<K, Collection<V>>newEnumMap(keyType), factory);
}