Example usage for com.google.common.collect HashMultimap create

List of usage examples for com.google.common.collect HashMultimap create

Introduction

In this page you can find the example usage for com.google.common.collect HashMultimap create.

Prototype

public static <K, V> HashMultimap<K, V> create() 

Source Link

Document

Creates a new, empty HashMultimap with the default initial capacities.

Usage

From source file:org.apache.rya.indexing.external.matching.BasicRater.java

private double getConnectedComponentRating(List<QueryModelNode> eNodes) {

    Multimap<String, Integer> commonVarBin = HashMultimap.create();

    // bin QueryModelNode positions according to variable names
    for (int i = 0; i < eNodes.size(); i++) {
        QueryModelNode node = eNodes.get(i);
        if (node instanceof TupleExpr) {
            TupleExpr tup = (TupleExpr) node;
            Set<String> bindingNames = tup.getAssuredBindingNames();
            for (String name : bindingNames) {
                if (!name.startsWith("-const-")) {
                    commonVarBin.put(name, i);
                }/*from   w ww  .j a  v  a2  s  .c o m*/
            }
        }
    }

    Set<List<Integer>> pairs = new HashSet<>();
    for (String var : commonVarBin.keySet()) {
        Set<Integer> pos = Sets.newHashSet(commonVarBin.get(var));
        pairs.addAll(Sets.cartesianProduct(pos, pos));
    }

    int numComponents = countComponents(eNodes.size(), pairs);
    return ((double) numComponents) / eNodes.size();

}

From source file:org.terasology.holdings.HoldingSystem.java

/**
 * Responsible for tick update - see if we should review thresholds (like making a new queen)
 *
 * @param delta time step since last update
 *///ww  w.jav  a  2s  .com
public void update(float delta) {
    // Do a time check to see if we should even bother calculating stuff (really only needed every second or so)
    // Keep a ms counter handy, delta is in seconds
    tick += delta * 1000;

    if (tick - classLastTick < 5000) {
        return;
    }
    classLastTick = tick;

    // Prep a list of the holdings we know about
    ArrayList<EntityRef> holdingEntities = new ArrayList<EntityRef>(4);

    // Go fetch all the Holdings.
    // TODO: Do we have a helper method for this? I forgot and it is late :P
    for (EntityRef holdingEntity : entityManager.getEntitiesWith(HoldingComponent.class)) {
        holdingEntities.add(holdingEntity);
    }

    // Prep a fancy multi map of the Holdings and which if any Spawnables belong to each
    SetMultimap<EntityRef, EntityRef> spawnableEntitiesByHolding = HashMultimap.create();

    // Loop through all Spawnables and assign them to a Holding if one exists that is also the Spawnables parent (its Spawner)
    for (EntityRef spawnableEntity : entityManager.getEntitiesWith(SpawnableComponent.class)) {

        for (EntityRef holdingEntity : holdingEntities) {

            // Check the spawnable's parent (a reference to a Spawner entity) against the holding (which we cheat-know to also be a Spawner)
            if (spawnableEntity.getComponent(SpawnableComponent.class).parent == holdingEntity) {
                // Map this Spawnable to its Holding
                spawnableEntitiesByHolding.put(holdingEntity, spawnableEntity);
                break;
            }
        }
    }

    // For each Holding check if there are enough Spawnables to create a queen
    for (EntityRef holdingEntity : holdingEntities) {
        Set<EntityRef> holdingSpawnables = spawnableEntitiesByHolding.get(holdingEntity);
        int spawnableCount = holdingSpawnables.size();
        HoldingComponent holdComp = holdingEntity.getComponent(HoldingComponent.class);
        logger.info("Processing a holding with a spawnableCount of {} and threshold of {}", spawnableCount,
                holdComp.queenThreshold);
        if (spawnableCount > holdComp.queenThreshold && holdComp.queenMax > holdComp.queenCurrent) {

            EntityRef queenInWaiting = null;
            // See if we have a candidate queen to crown
            for (EntityRef queenCandidate : holdingSpawnables) {
                // Come up with some criteria - for now just pick the first one
                queenInWaiting = queenCandidate;
            }

            if (queenInWaiting == null) {
                logger.info("We failed to find a worthy queen :-(");
                continue;
            }

            // After success make sure to increment the threshold and queen count (queen count never decrements, queens could disappear in the future)
            holdComp.queenThreshold += 10;
            holdComp.queenCurrent++;

            // Then prep the "crown" in the shape of a shiny new SpawnerComponent ;-)
            SpawnerComponent newSpawnerComp = new SpawnerComponent();
            newSpawnerComp.types.add("Oreon");
            newSpawnerComp.maxMobsPerSpawner = 50;
            newSpawnerComp.timeBetweenSpawns = 1000;
            /*
                            // Make the queen a unique color (in this case, black) TODO: With Oreons instead make the filling purple?
                            MeshComponent mesh = queenInWaiting.getComponent(MeshComponent.class);
                            if (mesh != null) {
            mesh.color.set(new Color4f(0, 0, 0, 1));
                            }
            */
            queenInWaiting.addComponent(newSpawnerComp);
            logger.info("Queen prepped, id {} and spawnercomp {}", queenInWaiting,
                    queenInWaiting.getComponent(SpawnerComponent.class));

        } else {
            logger.info("Haven't reached the threshold yet or queenMax {} is not greater than queenCurrent {}",
                    holdComp.queenMax, holdComp.queenCurrent);
        }
    }
}

From source file:de.fau.osr.core.db.CSVFileDataSource.java

@Override
public HashMultimap<String, String> doGetAllReqCommitRelations() throws IOException {
    HashMultimap<String, String> relations = HashMultimap.create();

    try (CSVReader reader = getReader()) {
        List<String[]> allLines = reader.readAll();
        String reqId;/*from  w  w w . j  a va  2  s. c om*/
        String commitId;
        for (String[] line : allLines) {
            reqId = line[REQUIREMENT_COLUMN];
            commitId = line[COMMIT_COLUMN];
            relations.put(reqId, commitId);
        }

    }
    return relations;
}

From source file:edu.umd.cs.psl.model.atom.GroundAtom.java

/**
 * Registers a ground kernel to receive update events.
 * <p>//from  w w  w .jav a 2 s.c om
 * Any GroundKernel that is a function of this Atom should be registered.
 * 
 * @param f A ground kernel
 * @return TRUE if successful; FALSE if kernel was already registered 
 */
public boolean registerGroundKernel(GroundKernel f) {
    if (registeredGroundKernels == null)
        registeredGroundKernels = HashMultimap.create();
    return registeredGroundKernels.put(f.getKernel(), f);
}

From source file:com.griddynamics.jagger.engine.e1.collector.MasterWorkloadCollector.java

private void putValues(String sessionId, String taskId, Collection<NodeId> capableNodes,
        WorkloadTask workload) {/*  ww  w.ja v  a  2 s.  c o  m*/
    Namespace sessionNamespace = Namespace.of(SESSION, sessionId);
    keyValueStorage.put(sessionNamespace, SCENARIOS, taskId);

    Namespace scenarioNamespace = Namespace.of(sessionId, taskId);
    Multimap<String, Object> objectsMap = HashMultimap.create();
    objectsMap.put(START_TIME, System.currentTimeMillis() + workload.getStartDelay());

    objectsMap.put(CLOCK, workload.getClock().toString());
    objectsMap.put(CLOCK_VALUE, workload.getClock().getValue());
    objectsMap.put(TERMINATION, workload.getTerminateStrategyConfiguration().toString());

    objectsMap.put(KERNEL_COUNT, capableNodes.size());
    for (NodeId nodeId : capableNodes) {
        String nodeStr = nodeId.toString();
        log.debug("kernels: {}", nodeStr);
        objectsMap.put(KERNELS, nodeStr);
    }
    keyValueStorage.putAll(scenarioNamespace, objectsMap);
}

From source file:edu.umd.cs.psl.database.RDBMS.RDBMSDataStore.java

public RDBMSDataStore(String valueColName, String confidenceColName, String pslColName,
        String partitionColName) {
    valueColumnSuffix = valueColName;/*from w  ww.  ja v  a2  s .co  m*/
    confidenceColumnSuffix = confidenceColName;
    pslColumnName = pslColName;
    partitionColumnName = partitionColName;

    predicates = new HashMap<Predicate, PredicateDBInfo>();
    openDatabases = HashMultimap.create();
    writePartitionIDs = new HashSet<Partition>();
}