Example usage for com.google.common.collect Multimaps newListMultimap

List of usage examples for com.google.common.collect Multimaps newListMultimap

Introduction

In this page you can find the example usage for com.google.common.collect Multimaps newListMultimap.

Prototype

public static <K, V> ListMultimap<K, V> newListMultimap(Map<K, Collection<V>> map,
        final Supplier<? extends List<V>> factory) 

Source Link

Document

Creates a new ListMultimap that uses the provided map and factory.

Usage

From source file:org.exolin.sudoku.solver.Sudoku.java

private boolean solveUnit(Iterable<SudokoCell> unit) throws InconsistenceException {
    ListMultimap<Integer, SudokoCell> possiblities = Multimaps.newListMultimap(new HashMap<>(), ArrayList::new);

    for (SudokoCell cell : unit) {
        for (int possibleNumber : cell.getPossibleValues()) {
            possiblities.put(possibleNumber, cell);
        }//from   ww  w . j a  va2s  . c o m
    }

    boolean progress = false;

    for (Entry<Integer, Collection<SudokoCell>> e : possiblities.asMap().entrySet()) {
        int possibleNumber = e.getKey();
        Collection<SudokoCell> possibleCells = e.getValue();

        if (possibleCells.size() == 1) {
            SudokoCell next = possibleCells.iterator().next();

            if (!next.isComplete()) {
                next.setNumber(possibleNumber);
                progress = true;
            }
        }
    }

    return progress;
}

From source file:org.napile.compiler.lang.resolve.calls.autocasts.DataFlowInfo.java

private ListMultimap<DataFlowValue, NapileType> copyTypeInfo() {
    ListMultimap<DataFlowValue, NapileType> newTypeInfo = Multimaps.newListMultimap(
            Maps.<DataFlowValue, Collection<NapileType>>newHashMap(),
            CommonSuppliers.<NapileType>getArrayListSupplier());
    newTypeInfo.putAll(typeInfo);/*from   w  w  w. j  a  v a  2s .c  om*/
    return newTypeInfo;
}

From source file:com.android.tools.lint.checks.ResourceCycleDetector.java

private void recordReference(@NonNull ResourceType type, @NonNull String from, @NonNull String to) {
    if (to.isEmpty() || to.startsWith(ANDROID_PREFIX)) {
        return;/* w  w w.  j  av a 2 s. c  om*/
    }
    assert mReferences != null;
    Multimap<String, String> map = mReferences.get(type);
    if (map == null) {
        // Multimap which preserves insert order (for predictable output order)
        map = Multimaps.newListMultimap(new TreeMap<String, Collection<String>>(),
                new Supplier<List<String>>() {
                    @Override
                    public List<String> get() {
                        return Lists.newArrayListWithExpectedSize(6);
                    }
                });
        mReferences.put(type, map);
    }

    if (to.charAt(0) == '@') {
        int index = to.indexOf('/');
        if (index != -1) {
            to = to.substring(index + 1);
        }
    }

    map.put(from, to);
}

From source file:com.demigodsrpg.data.battle.Report.java

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);
        }/*ww w. java2  s.  c  o m*/
        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;
}

From source file:org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo.java

public DataFlowInfo or(DataFlowInfo other) {
    Map<DataFlowValue, Nullability> builder = Maps.newHashMap(nullabilityInfo);
    builder.keySet().retainAll(other.nullabilityInfo.keySet());
    for (Map.Entry<DataFlowValue, Nullability> entry : builder.entrySet()) {
        DataFlowValue key = entry.getKey();
        Nullability thisFlags = entry.getValue();
        Nullability otherFlags = other.nullabilityInfo.get(key);
        assert (otherFlags != null);
        builder.put(key, thisFlags.or(otherFlags));
    }/*w  w w  . j av  a2  s.  c  o m*/

    ListMultimap<DataFlowValue, JetType> newTypeInfo = Multimaps.newListMultimap(
            Maps.<DataFlowValue, Collection<JetType>>newHashMap(),
            CommonSuppliers.<JetType>getArrayListSupplier());

    Set<DataFlowValue> keys = Sets.newHashSet(typeInfo.keySet());
    keys.retainAll(other.typeInfo.keySet());

    for (DataFlowValue key : keys) {
        Collection<JetType> thisTypes = typeInfo.get(key);
        Collection<JetType> otherTypes = other.typeInfo.get(key);

        Collection<JetType> newTypes = Sets.newHashSet(thisTypes);
        newTypes.retainAll(otherTypes);

        newTypeInfo.putAll(key, newTypes);
    }

    return new DataFlowInfo(ImmutableMap.copyOf(builder), newTypeInfo);
}

From source file:com.facebook.buck.cxx.CxxToolchainDescription.java

@Override
public BuildRule createBuildRule(BuildRuleCreationContextWithTargetGraph context, BuildTarget buildTarget,
        BuildRuleParams params, CxxToolchainDescriptionArg args) {
    BuildRuleResolver ruleResolver = context.getActionGraphBuilder();

    CxxPlatform.Builder cxxPlatform = CxxPlatform.builder();

    // TODO(cjhopman): Support these when we need them.
    cxxPlatform.setCuda(Optional.empty());
    cxxPlatform.setCudapp(Optional.empty());
    cxxPlatform.setHip(Optional.empty());
    cxxPlatform.setHippp(Optional.empty());
    cxxPlatform.setAsm(Optional.empty());

    cxxPlatform.setCudaflags(ImmutableList.of());
    cxxPlatform.setCudappflags(ImmutableList.of());
    cxxPlatform.setHipflags(ImmutableList.of());
    cxxPlatform.setHipppflags(ImmutableList.of());
    cxxPlatform.setAsmflags(ImmutableList.of());

    if (args.getUseHeaderMap()) {
        cxxPlatform.setHeaderMode(HeaderMode.SYMLINK_TREE_WITH_HEADER_MAP);
    } else {/*w ww  . ja  v a  2s  .com*/
        cxxPlatform.setHeaderMode(HeaderMode.SYMLINK_TREE_ONLY);
    }

    // TODO(cjhopman): How to handle this?
    cxxPlatform.setFlagMacros(ImmutableMap.of());

    cxxPlatform.setConflictingHeaderBasenameWhitelist(ImmutableSortedSet.of());

    // Below here are all the things that we actually support configuration of. They mostly match
    // CxxPlatform, but (1) are in some cases more restrictive and (2) use more descriptive names.
    cxxPlatform.setPrivateHeadersSymlinksEnabled(args.getPrivateHeadersSymlinksEnabled());
    cxxPlatform.setPublicHeadersSymlinksEnabled(args.getPublicHeadersSymlinksEnabled());

    cxxPlatform.setUseArgFile(args.getUseArgFile());

    cxxPlatform.setSharedLibraryExtension(args.getSharedLibraryExtension());
    cxxPlatform.setSharedLibraryVersionedExtensionFormat(args.getSharedLibraryVersionedExtensionFormat());
    cxxPlatform.setStaticLibraryExtension(args.getStaticLibraryExtension());
    cxxPlatform.setObjectFileExtension(args.getObjectFileExtension());
    cxxPlatform.setBinaryExtension(args.getBinaryExtension());

    CxxToolProvider.Type compilerType = args.getCompilerType();
    LinkerProvider.Type linkerType = args.getLinkerType();
    // This should be the same for all the tools that use it.
    final boolean preferDependencyTree = false;

    cxxPlatform.setAs(new CompilerProvider(ToolProviders.getToolProvider(args.getAssembler()), compilerType,
            preferDependencyTree));
    cxxPlatform.setAsflags(args.getAssemblerFlags());

    cxxPlatform.setAspp(
            new PreprocessorProvider(ToolProviders.getToolProvider(args.getAssembler()), compilerType));
    cxxPlatform.setAsppflags(ImmutableList.of());

    cxxPlatform.setCc(new CompilerProvider(ToolProviders.getToolProvider(args.getCCompiler()), compilerType,
            preferDependencyTree));
    cxxPlatform.setCflags(args.getCCompilerFlags());

    cxxPlatform.setCxx(new CompilerProvider(ToolProviders.getToolProvider(args.getCxxCompiler()), compilerType,
            preferDependencyTree));
    cxxPlatform.setCxxflags(args.getCxxCompilerFlags());

    cxxPlatform
            .setCpp(new PreprocessorProvider(ToolProviders.getToolProvider(args.getCCompiler()), compilerType));
    cxxPlatform.setCppflags(ImmutableList.of());

    cxxPlatform.setCxxpp(
            new PreprocessorProvider(ToolProviders.getToolProvider(args.getCxxCompiler()), compilerType));
    cxxPlatform.setCxxppflags(ImmutableList.of());

    cxxPlatform.setLd(
            new DefaultLinkerProvider(linkerType, ToolProviders.getToolProvider(args.getLinker()), true));

    if (linkerType == LinkerProvider.Type.GNU || linkerType == LinkerProvider.Type.DARWIN) {
        cxxPlatform.setLdflags(ImmutableList.<String>builder()
                // Add a deterministic build ID.
                .add("-Wl,--build-id").addAll(args.getLinkerFlags()).build());
    } else {
        // TODO(cjhopman): We should force build ids by default for all linkers.
        cxxPlatform.setLdflags(args.getLinkerFlags());
    }

    cxxPlatform.setAr(
            ArchiverProvider.from(ToolProviders.getToolProvider(args.getArchiver()), args.getArchiverType()));
    cxxPlatform.setArflags(args.getArchiverFlags());

    cxxPlatform.setStrip(ToolProviders.getToolProvider(args.getStrip()).resolve(ruleResolver));
    cxxPlatform.setStripFlags(args.getStripFlags());

    cxxPlatform.setRanlib(args.getRanlib().map(ToolProviders::getToolProvider));
    cxxPlatform.setRanlibflags(args.getRanlibFlags());

    ListMultimap<LinkableDepType, String> runtimeLdFlags = Multimaps.newListMultimap(new LinkedHashMap<>(),
            ArrayList::new);
    runtimeLdFlags.putAll(LinkableDepType.STATIC, args.getStaticDepRuntimeLdFlags());
    runtimeLdFlags.putAll(LinkableDepType.STATIC_PIC, args.getStaticPicDepRuntimeLdFlags());
    runtimeLdFlags.putAll(LinkableDepType.SHARED, args.getSharedDepRuntimeLdFlags());
    cxxPlatform.setRuntimeLdflags(runtimeLdFlags);

    cxxPlatform.setSymbolNameTool(
            new PosixNmSymbolNameTool(ToolProviders.getToolProvider(args.getNm()).resolve(ruleResolver)));

    // User-configured cxx platforms are required to handle path sanitization themselves.
    cxxPlatform.setCompilerDebugPathSanitizer(NoopDebugPathSanitizer.INSTANCE);
    cxxPlatform.setAssemblerDebugPathSanitizer(NoopDebugPathSanitizer.INSTANCE);

    // We require that untracked headers are errors and don't allow any whitelisting (the
    // user-configured platform can implement it's only filtering of the produced depfiles).
    cxxPlatform.setHeaderVerification(
            HeaderVerification.of(HeaderVerification.Mode.ERROR, ImmutableList.of(), ImmutableList.of()));

    SharedLibraryInterfaceParams.Type sharedLibraryInterfaceType = args.getSharedLibraryInterfaceType();
    // TODO(cjhopman): We should change this to force users to implement all of the shared library
    // interface logic.
    if (sharedLibraryInterfaceType == Type.DISABLED) {
        cxxPlatform.setSharedLibraryInterfaceParams(Optional.empty());
    } else {
        cxxPlatform.setSharedLibraryInterfaceParams(ElfSharedLibraryInterfaceParams.of(
                ToolProviders.getToolProvider(args.getObjcopyForSharedLibraryInterface()), ImmutableList.of(),
                sharedLibraryInterfaceType == Type.DEFINED_ONLY));
    }

    // TODO(cjhopman): Is this reasonable?
    cxxPlatform.setConflictingHeaderBasenameWhitelist(ImmutableSortedSet.of());

    cxxPlatform.setArchiveContents(ArchiveContents.NORMAL);

    cxxPlatform.setFilepathLengthLimited(args.getFilepathLengthLimited());

    return new CxxToolchainBuildRule(buildTarget, context, cxxPlatform);
}

From source file:org.napile.compiler.lang.resolve.calls.autocasts.DataFlowInfo.java

public DataFlowInfo or(DataFlowInfo other) {
    Map<DataFlowValue, Nullability> builder = Maps.newHashMap(nullabilityInfo);
    builder.keySet().retainAll(other.nullabilityInfo.keySet());
    for (Map.Entry<DataFlowValue, Nullability> entry : builder.entrySet()) {
        DataFlowValue key = entry.getKey();
        Nullability thisFlags = entry.getValue();
        Nullability otherFlags = other.nullabilityInfo.get(key);
        assert (otherFlags != null);
        builder.put(key, thisFlags.or(otherFlags));
    }/*from   w  ww . j  av a2 s .co m*/

    ListMultimap<DataFlowValue, NapileType> newTypeInfo = Multimaps.newListMultimap(
            Maps.<DataFlowValue, Collection<NapileType>>newHashMap(),
            CommonSuppliers.<NapileType>getArrayListSupplier());

    Set<DataFlowValue> keys = Sets.newHashSet(typeInfo.keySet());
    keys.retainAll(other.typeInfo.keySet());

    for (DataFlowValue key : keys) {
        Collection<NapileType> thisTypes = typeInfo.get(key);
        Collection<NapileType> otherTypes = other.typeInfo.get(key);

        Collection<NapileType> newTypes = Sets.newHashSet(thisTypes);
        newTypes.retainAll(otherTypes);

        newTypeInfo.putAll(key, newTypes);
    }

    return new DataFlowInfo(ImmutableMap.copyOf(builder), newTypeInfo);
}

From source file:com.demigodsrpg.data.battle.Report.java

public Multimap<Faction, String> getFactionScores() {
    Multimap<Faction, String> scores = Multimaps.newListMultimap(new ConcurrentHashMap<>(), ArrayList::new);
    Map<Faction, BattleMetaData> factionScores = new HashMap<>();
    for (Map.Entry<String, BattleMetaData> entry : battle.getInvolved().entrySet()) {
        Participant participant = DGData.PLAYER_R.fromId(entry.getKey());
        Faction participantFaction = participant.getFaction();
        BattleMetaData participantData = entry.getValue();
        BattleMetaData factionData = factionScores.getOrDefault(participantFaction, new BattleMetaData());
        factionData.hits += participantData.hits;
        factionData.kills += participantData.kills;
        factionData.deaths += participantData.deaths;
        factionData.denies += participantData.denies;
        factionData.assists += participantData.assists;
        factionData.teamKills += participantData.teamKills;
        factionScores.put(participantFaction, factionData);
    }/* w  ww .java 2 s .  c om*/
    for (Map.Entry<Faction, BattleMetaData> entry : factionScores.entrySet()) {
        scores.put(entry.getKey(), ChatColor.DARK_GRAY + "  " + ChatColor.YELLOW + "Hits: " + ChatColor.WHITE
                + entry.getValue().hits);
        scores.put(entry.getKey(), ChatColor.DARK_GRAY + "  " + ChatColor.YELLOW + "Kills: "
                + ChatColor.WHITE + entry.getValue().kills);
        scores.put(entry.getKey(), ChatColor.DARK_GRAY + "  " + ChatColor.YELLOW + "Deaths: "
                + ChatColor.WHITE + entry.getValue().deaths);
        scores.put(entry.getKey(), ChatColor.DARK_GRAY + "  " + ChatColor.YELLOW + "Denies: "
                + ChatColor.WHITE + entry.getValue().denies);
        scores.put(entry.getKey(), ChatColor.DARK_GRAY + "  " + ChatColor.YELLOW + "Assists: "
                + ChatColor.WHITE + entry.getValue().assists);
    }
    return scores;
}

From source file:org.sosy_lab.cpachecker.cpa.predicate.PredicateAbstractionRefinementStrategy.java

@Override
public void startRefinementOfPath() {
    checkState(newPredicates == null);//www.j a v a2  s . c o m
    // needs to be a fully deterministic data structure,
    // thus a Multimap based on a LinkedHashMap
    // (we iterate over the keys)
    newPredicates = Multimaps.newListMultimap(
            new LinkedHashMap<Pair<CFANode, Integer>, Collection<AbstractionPredicate>>(),
            new Supplier<List<AbstractionPredicate>>() {
                @Override
                public List<AbstractionPredicate> get() {
                    return new ArrayList<>();
                }
            });
}

From source file:com.iorga.webappwatcher.analyzer.model.session.RequestsTimesAndStacks.java

private static <K, V> ListMultimap<K, V> newListMultimap() {
    return Multimaps.newListMultimap(Maps.<K, Collection<V>>newHashMap(), new GenericListSupplier<V>());
}