Example usage for com.google.common.collect Multimap put

List of usage examples for com.google.common.collect Multimap put

Introduction

In this page you can find the example usage for com.google.common.collect Multimap put.

Prototype

boolean put(@Nullable K key, @Nullable V value);

Source Link

Document

Stores a key-value pair in this multimap.

Usage

From source file:grakn.core.graql.gremlin.RelationTypeInference.java

private static Multimap<Variable, Type> getInstanceVarTypeMap(Set<Fragment> allFragments,
        Map<Variable, Type> labelVarTypeMap) {
    Multimap<Variable, Type> instanceVarTypeMap = HashMultimap.create();
    int oldSize;//from   w w  w .  j a v  a  2 s  . c o m
    do {
        oldSize = instanceVarTypeMap.size();
        allFragments.stream().filter(fragment -> labelVarTypeMap.containsKey(fragment.start())) // restrict to types
                .filter(fragment -> fragment instanceof InIsaFragment || fragment instanceof InSubFragment) //
                .forEach(fragment -> instanceVarTypeMap.put(fragment.end(),
                        labelVarTypeMap.get(fragment.start())));
    } while (oldSize != instanceVarTypeMap.size());
    return instanceVarTypeMap;
}

From source file:eu.itesla_project.iidm.eurostag.export.BranchParallelIndexes.java

public static BranchParallelIndexes build(Network network, EurostagEchExportConfig config) {
    Multimap<String, Identifiable> map = HashMultimap.create();
    for (TwoTerminalsConnectable ttc : Iterables.concat(network.getLines(),
            network.getTwoWindingsTransformers())) {
        ConnectionBus bus1 = ConnectionBus.fromTerminal(ttc.getTerminal1(), config, EchUtil.FAKE_NODE_NAME1);
        ConnectionBus bus2 = ConnectionBus.fromTerminal(ttc.getTerminal2(), config, EchUtil.FAKE_NODE_NAME2);
        if (bus1.getId().compareTo(bus2.getId()) < 0) {
            map.put(bus1.getId() + bus2.getId(), ttc);
        } else {/*from  w  ww . j ava  2  s  . co  m*/
            map.put(bus2.getId() + bus1.getId(), ttc);
        }
    }
    for (VoltageLevel vl : network.getVoltageLevels()) {
        for (Switch s : EchUtil.getSwitches(vl, config)) {
            Bus bus1 = EchUtil.getBus1(vl, s.getId(), config);
            Bus bus2 = EchUtil.getBus2(vl, s.getId(), config);
            if (bus1.getId().compareTo(bus2.getId()) < 0) {
                map.put(bus1.getId() + bus2.getId(), s);
            } else {
                map.put(bus2.getId() + bus1.getId(), s);
            }
        }
    }
    Map<String, Character> parallelIndexes = new HashMap<>();
    for (Map.Entry<String, Collection<Identifiable>> entry : map.asMap().entrySet()) {
        List<Identifiable> eqs = new ArrayList<>(entry.getValue());
        Collections.sort(eqs, (o1, o2) -> o1.getId().compareTo(o2.getId()));
        if (eqs.size() >= 2) {
            char index = '0';
            for (Identifiable l : eqs) {
                index = incParallelIndex(index);
                parallelIndexes.put(l.getId(), index);
            }
        }
    }
    return new BranchParallelIndexes(parallelIndexes);
}

From source file:org.hudsonci.plugins.vault.util.MultimapUtil.java

public static void load(final Multimap<String, String> map, final Reader source) throws IOException {
    assert map != null;
    assert source != null;

    BufferedReader reader = new BufferedReader(source);
    String line;//from w  w w  . j av  a2 s  .com
    while ((line = reader.readLine()) != null) {
        String[] items = line.split("=", 2);
        String key = items[0].trim();
        String value = null;
        if (items.length == 2) {
            value = items[1].trim();
        }
        map.put(key, value);
    }
}

From source file:aritzh.waywia.universe.World.java

private static Multimap<String, Entity> readEntities(BDSCompound entitiesComp) {
    Multimap<String, Entity> entities = ArrayListMultimap.create();
    for (BDSCompound comp : entitiesComp.getAllCompounds()) {
        if (!comp.getName().equals("Entity"))
            continue;
        try {//www.j a  v a2  s .  c  o  m
            Entity e = Entity.fromBDS(comp);

            if (e != null)
                entities.put(e.getName(), e);
        } catch (Exception ignored) {
        }
    }
    return entities;
}

From source file:cuchaz.enigma.analysis.EntryRenamer.java

public static <Key, Val> void renameClassesInMultimap(Map<String, String> renames, Multimap<Key, Val> map) {
    // for each key/value pair...
    Set<Map.Entry<Key, Val>> entriesToAdd = Sets.newHashSet();
    for (Map.Entry<Key, Val> entry : map.entries()) {
        entriesToAdd.add(new AbstractMap.SimpleEntry<>(renameClassesInThing(renames, entry.getKey()),
                renameClassesInThing(renames, entry.getValue())));
    }//www  . j a  va2s . co m
    map.clear();
    for (Map.Entry<Key, Val> entry : entriesToAdd) {
        map.put(entry.getKey(), entry.getValue());
    }
}

From source file:cuchaz.enigma.analysis.EntryRenamer.java

public static <Key, Val> void renameMethodsInMultimap(Map<MethodEntry, MethodEntry> renames,
        Multimap<Key, Val> map) {
    // for each key/value pair...
    Set<Map.Entry<Key, Val>> entriesToAdd = Sets.newHashSet();
    for (Map.Entry<Key, Val> entry : map.entries()) {
        entriesToAdd.add(new AbstractMap.SimpleEntry<>(renameMethodsInThing(renames, entry.getKey()),
                renameMethodsInThing(renames, entry.getValue())));
    }/*from   w  w w  . jav a  2  s.  co  m*/
    map.clear();
    for (Map.Entry<Key, Val> entry : entriesToAdd) {
        map.put(entry.getKey(), entry.getValue());
    }
}

From source file:grakn.core.graql.executor.WriteExecutor.java

private static Multimap<VarProperty, Variable> propertyToEquivalentVars(Set<Writer> executors) {
    Multimap<VarProperty, Variable> equivalentProperties = HashMultimap.create();

    for (Writer executor : executors) {
        if (executor.property().uniquelyIdentifiesConcept()) {
            equivalentProperties.put(executor.property(), executor.var());
        }/*from www .  jav  a 2 s .  co  m*/
    }

    return equivalentProperties;
}

From source file:it.osm.gtfs.input.GTFSParser.java

public static Multimap<String, Trip> groupTrip(List<Trip> trips, Map<String, Route> routes,
        Map<String, StopsList> stopTimes) {
    Collections.sort(trips);//from  w w  w.  ja  va 2 s  .  c  o m
    Multimap<String, Trip> result = ArrayListMultimap.create();
    for (Trip t : trips) {
        Route r = routes.get(t.getRoute().getId());
        StopsList s = stopTimes.get(t.getTripID());

        if (s.isValid()) {
            result.put(r.getShortName(), t);
        }
    }
    return result;
}

From source file:org.apache.cassandra.tools.SSTableExpiredBlockers.java

public static Multimap<SSTableReader, SSTableReader> checkForExpiredSSTableBlockers(
        Iterable<SSTableReader> sstables, int gcBefore) {
    Multimap<SSTableReader, SSTableReader> blockers = ArrayListMultimap.create();
    for (SSTableReader sstable : sstables) {
        if (sstable.getSSTableMetadata().maxLocalDeletionTime < gcBefore) {
            for (SSTableReader potentialBlocker : sstables) {
                if (!potentialBlocker.equals(sstable)
                        && potentialBlocker.getMinTimestamp() <= sstable.getMaxTimestamp()
                        && potentialBlocker.getSSTableMetadata().maxLocalDeletionTime > gcBefore)
                    blockers.put(potentialBlocker, sstable);
            }/*  w w  w.ja v a  2  s  .  com*/
        }
    }
    return blockers;
}

From source file:com.google.devtools.build.android.resources.ResourceSymbols.java

/**
 * Loads the SymbolTables from a list of SymbolFileProviders.
 *
 * @param dependencies The full set of library symbols to load.
 * @param executor The executor use during loading.
 * @param iLogger Android logger to use.
 * @param packageToExclude A string package to elide if it exists in the providers.
 * @return A list of loading {@link ResourceSymbols} instances.
 * @throws ExecutionException//from www. j a v  a 2 s  .c  o m
 * @throws InterruptedException when there is an error loading the symbols.
 */
public static Multimap<String, ListenableFuture<ResourceSymbols>> loadFrom(
        Collection<SymbolFileProvider> dependencies, ListeningExecutorService executor, ILogger iLogger,
        @Nullable String packageToExclude) throws InterruptedException, ExecutionException {
    Map<SymbolFileProvider, ListenableFuture<String>> providerToPackage = new HashMap<>();
    for (SymbolFileProvider dependency : dependencies) {
        providerToPackage.put(dependency, executor.submit(new PackageParsingTask(dependency.getManifest())));
    }
    Multimap<String, ListenableFuture<ResourceSymbols>> packageToTable = HashMultimap.create();
    for (Entry<SymbolFileProvider, ListenableFuture<String>> entry : providerToPackage.entrySet()) {
        File symbolFile = entry.getKey().getSymbolFile();
        if (!Objects.equals(entry.getValue().get(), packageToExclude)) {
            packageToTable.put(entry.getValue().get(), load(symbolFile.toPath(), executor));
        }
    }
    return packageToTable;
}