本文整理汇总了Java中com.google.common.collect.Multimaps.newListMultimap方法的典型用法代码示例。如果您正苦于以下问题:Java Multimaps.newListMultimap方法的具体用法?Java Multimaps.newListMultimap怎么用?Java Multimaps.newListMultimap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.Multimaps
的用法示例。
在下文中一共展示了Multimaps.newListMultimap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: detectPotentialLocksCycle
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
/**
* Algorithm to detect a potential lock cycle.
*
* For lock's thread owner check which lock is it trying to take.
* Repeat recursively. When current thread is found a potential cycle is detected.
*
* @see CycleDetectingLock#lockOrDetectPotentialLocksCycle()
*/
private ListMultimap<Long, ID> detectPotentialLocksCycle() {
final long currentThreadId = Thread.currentThread().getId();
if (lockOwnerThreadId == null || lockOwnerThreadId == currentThreadId) {
// if nobody owns this lock, lock cycle is impossible
// if a current thread owns this lock, we let Guice to handle it
return ImmutableListMultimap.of();
}
ListMultimap<Long, ID> potentialLocksCycle = Multimaps.newListMultimap(
new LinkedHashMap<Long, Collection<ID>>(),
new Supplier<List<ID>>() {
@Override
public List<ID> get() {
return Lists.newArrayList();
}
});
// lock that is a part of a potential locks cycle, starts with current lock
ReentrantCycleDetectingLock lockOwnerWaitingOn = this;
// try to find a dependency path between lock's owner thread and a current thread
while (lockOwnerWaitingOn != null && lockOwnerWaitingOn.lockOwnerThreadId != null) {
Long threadOwnerThreadWaits = lockOwnerWaitingOn.lockOwnerThreadId;
// in case locks cycle exists lock we're waiting for is part of it
potentialLocksCycle.putAll(threadOwnerThreadWaits,
getAllLockIdsAfter(threadOwnerThreadWaits, lockOwnerWaitingOn));
if (threadOwnerThreadWaits == currentThreadId) {
// owner thread depends on current thread, cycle detected
return potentialLocksCycle;
}
// going for the next thread we wait on indirectly
lockOwnerWaitingOn = lockThreadIsWaitingOn.get(threadOwnerThreadWaits);
}
// no dependency path from an owner thread to a current thread
return ImmutableListMultimap.of();
}
示例2: testTransOldType2Multimap
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
/**
* 将原始写法转成Multimap
*/
@Test
public void testTransOldType2Multimap() {
// 原始的实现形式
Map<String, Collection<String>> hashMap = Maps.newHashMap();
Collection<String> listStrs = Lists.newArrayList("aaa", "ccc", "bbb");
hashMap.put("list_1", listStrs);
// 转成Multimap
ListMultimap<String, String> multiMap = Multimaps.newListMultimap(hashMap, LinkedList::new);
System.out.println(multiMap);
}
示例3: newLinkedHashListMultimap
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
/**
* Creates a new, empty {@code ListMultimap} with the default initial capacities that uses a linked map internally.
*/
public static <K, V> ListMultimap<K, V> newLinkedHashListMultimap() {
return Multimaps.newListMultimap(Maps.<K, Collection<V>> newLinkedHashMap(), new Supplier<List<V>>() {
@Override
public List<V> get() {
return Lists.newArrayList();
}
});
}
示例4: createParamsMultimap
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
protected static Multimap<String, String> createParamsMultimap() {
return Multimaps.<String, String> newListMultimap(new LinkedHashMap<String, Collection<String>>(),
new Supplier<ArrayList<String>>() {
@Override
public ArrayList<String> get() {
return new ArrayList<String>();
}
});
}
示例5: JobClassInfo
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
public JobClassInfo(ProcessingEnvironment env) {
mProcEnv = env;
mErrorReporter = new ErrorReporter(env);
mJobInfo = Multimaps.newListMultimap(
new HashMap<String, Collection<FieldInfo>>(),
new Supplier<List<FieldInfo>>() {
@Override
public List<FieldInfo> get() {
return Lists.newArrayList();
}
});
}
示例6: detectPotentialLocksCycle
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
/**
* Algorithm to detect a potential lock cycle.
*
* <p>For lock's thread owner check which lock is it trying to take. Repeat recursively. When
* current thread is found a potential cycle is detected.
*
* @see CycleDetectingLock#lockOrDetectPotentialLocksCycle()
*/
private ListMultimap<Thread, ID> detectPotentialLocksCycle() {
final Thread currentThread = Thread.currentThread();
if (lockOwnerThread == null || lockOwnerThread == currentThread) {
// if nobody owns this lock, lock cycle is impossible
// if a current thread owns this lock, we let Guice to handle it
return ImmutableListMultimap.of();
}
ListMultimap<Thread, ID> potentialLocksCycle =
Multimaps.newListMultimap(
new LinkedHashMap<Thread, Collection<ID>>(),
new Supplier<List<ID>>() {
@Override
public List<ID> get() {
return Lists.newArrayList();
}
});
// lock that is a part of a potential locks cycle, starts with current lock
ReentrantCycleDetectingLock<?> lockOwnerWaitingOn = this;
// try to find a dependency path between lock's owner thread and a current thread
while (lockOwnerWaitingOn != null && lockOwnerWaitingOn.lockOwnerThread != null) {
Thread threadOwnerThreadWaits = lockOwnerWaitingOn.lockOwnerThread;
// in case locks cycle exists lock we're waiting for is part of it
lockOwnerWaitingOn =
addAllLockIdsAfter(threadOwnerThreadWaits, lockOwnerWaitingOn, potentialLocksCycle);
if (threadOwnerThreadWaits == currentThread) {
// owner thread depends on current thread, cycle detected
return potentialLocksCycle;
}
}
// no dependency path from an owner thread to a current thread
return ImmutableListMultimap.of();
}
示例7: updateOsuDb
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
/**
* Parses the current osu database.
*/
public void updateOsuDb() {
try {
OsuDbFile db = OsuDbFile.parse(settings.getOsuDbPath());
Multimap<String, OsuBeatmapInfo> beatmaps =
Multimaps.newListMultimap(new HashMap<>(), ArrayList::new);
Stream.of(db.getBeatmaps()).forEach(
map -> beatmaps.put(
String.format("%s - %s [%s]", map.getArtistName(), map.getSongTitle(),
map.getDifficulty()), map));
this.beatmaps = beatmaps;
} catch (Exception e) {
log.error("error while reading osu db", e);
}
}
示例8: getParticipantScores
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
public Multimap<Participant, String> getParticipantScores() {
Multimap<Participant, String> scores = Multimaps.newListMultimap(new ConcurrentHashMap<>(), ArrayList::new);
for (Map.Entry<String, BattleMetaData> entry : battle.getInvolved().entrySet()) {
Participant participant = DGData.PLAYER_R.fromId(entry.getKey());
if (entry.getValue().hits > 0) {
scores.put(participant, ChatColor.DARK_GRAY + " ➥ " + ChatColor.YELLOW + "Hits: " + ChatColor.WHITE +
entry.getValue().hits);
}
if (entry.getValue().kills > 0) {
scores.put(participant, ChatColor.DARK_GRAY + " ➥ " + ChatColor.YELLOW + "Kills: " + ChatColor.WHITE +
entry.getValue().kills);
}
if (entry.getValue().deaths > 0) {
scores.put(participant, ChatColor.DARK_GRAY + " ➥ " + ChatColor.YELLOW + "Deaths: " + ChatColor.WHITE +
entry.getValue().deaths);
}
if (entry.getValue().denies > 0) {
scores.put(participant, ChatColor.DARK_GRAY + " ➥ " + ChatColor.YELLOW + "Denies: " + ChatColor.WHITE +
entry.getValue().denies);
}
if (entry.getValue().assists > 0) {
scores.put(participant, ChatColor.DARK_GRAY + " ➥ " + ChatColor.YELLOW + "Assists: " + ChatColor.WHITE +
entry.getValue().assists);
}
if (entry.getValue().teamKills > 0) {
scores.put(participant, ChatColor.DARK_GRAY + " ➥ " + ChatColor.RED + "Team kills: " + ChatColor.WHITE +
entry.getValue().teamKills);
}
}
return scores;
}
示例9: result
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
private static ListMultimap<String, ExprNode> result ()
{
return Multimaps.newListMultimap(Maps.<String, Collection<ExprNode>>newHashMap(), new Supplier<List<ExprNode>>() {
@Override
public List<ExprNode> get ()
{
return new LinkedList<>();
}
});
}
示例10: newCopyOnWritetListMultimap
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
public static <K, V>ListMultimap<K, V> newCopyOnWritetListMultimap() {
return Multimaps.newListMultimap(new ConcurrentHashMap<K, Collection<V>>(), new Supplier<List<V>>() {
@Override
public List<V> get() {
return new CopyOnWriteArrayList<V>();
}
});
}
示例11: newLinkedKeyArrayValueMultimap
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
private Multimap<K, String> newLinkedKeyArrayValueMultimap() {
return Multimaps.newListMultimap(
new LinkedHashMap<K, Collection<String>>(),
new Supplier<List<String>>() {
@Override public List<String> get() {
return Lists.newArrayList();
}
});
}
示例12: runWsimport
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
/**
* Run wsimport on a WSDL file
*
* @param baseDir Base directory
* @param wsdlFile WSDL file to compile
*/
protected void runWsimport(Path baseDir, Path wsdlFile) {
JavaExecAction action = getActionFactory().newJavaExecAction();
String packageName = Optional.ofNullable(wsdlFile.getParent()).map(p -> PACKAGE_JOINER.join(p)).orElse(null);
Multimap<String, Object> options = Multimaps.newListMultimap(new HashMap<>(), () -> new ArrayList<>());
if (packageName != null) {
options.put("p", packageName);
}
options.put("wsdllocation", wsdlFile.getFileName().toString());
options.put("s", getDestinationDir());
options.put("extension", true);
options.put("Xnocompile", true);
options.put("B-classpath", getProject().getConfigurations().getAt("xjc").getAsPath());
for (String extension : getXjcExtensions()) {
options.put("B-X" + extension, true);
}
if (getProject().getLogger().isDebugEnabled()) {
options.put("Xdebug", true);
}
else {
options.put("quiet", true);
}
for (File bindingFile : Objects.requireNonNull(getBindings()).getFiles()) {
if (bindingFile.isFile()) {
options.put("b", bindingFile);
}
}
List<String> arguments = createArguments(options);
arguments.add(wsdlFile.toString());
getLogger().debug("Running wsimport with arguments {}", Joiner.on(' ').join(arguments));
action.setArgs(arguments);
action.setClasspath(getProject().getConfigurations().getAt("jaxws"));
action.setMain("com.sun.tools.ws.WsImport");
action.setWorkingDir(baseDir.toFile());
ExecResult result = action.execute();
if (result.getExitValue() != 0) {
throw new GradleException("Error running wsimport");
}
}
示例13: newMultimap
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
private static <T> Multimap<ModelProcessingPhase, T> newMultimap() {
return Multimaps.newListMultimap(new EnumMap<>(ModelProcessingPhase.class), () -> new ArrayList<>(1));
}
示例14: getMultiMap
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
public static <K,V> ListMultimap<K,V> getMultiMap(Class<V> clazz) {
return Multimaps.newListMultimap(
new HashMap<K, java.util.Collection<V>>(), () -> new ArrayList<V>(clazz));
}
示例15: getMultiMap
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
public static <K,V> Multimap<K,V> getMultiMap(Class<V> clazz) {
return Multimaps.newListMultimap(
new HashMap<K, java.util.Collection<V>>(), () -> new LinkedList<V>(clazz));
}