当前位置: 首页>>代码示例>>Java>>正文


Java Multimaps.newMultimap方法代码示例

本文整理汇总了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;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:19,代码来源:Validator.java

示例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;
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:37,代码来源:CheckJavaValidator.java

示例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);
      }
    }
  }
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:38,代码来源:CheckJavaValidator.java

示例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();
    }
    
  });
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:11,代码来源:InMemoryLKVLiveMarketDataProvider.java

示例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;
}
 
开发者ID:vizpub,项目名称:vizpub,代码行数:15,代码来源:MultimapDeserializer.java

示例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());
        }
    });
}
 
开发者ID:HATB0T,项目名称:RuneCraftery,代码行数:14,代码来源:ModLoaderClientHelper.java

示例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);
}
 
开发者ID:joshng,项目名称:papaya,代码行数:4,代码来源:MoreCollections.java


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