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

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

Introduction

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

Prototype

Collection<V> get(@Nullable K key);

Source Link

Document

Returns a view collection of the values associated with key in this multimap, if any.

Usage

From source file:com.griddynamics.jagger.storage.rdb.HibernateKeyValueStorage.java

public void putAll(Namespace namespace, Multimap<String, Object> valuesMap) {
    Session session = null;/*w ww.j a va 2s  .  c om*/
    int count = 0;
    try {
        session = getHibernateTemplate().getSessionFactory().openSession();
        session.beginTransaction();
        for (String key : valuesMap.keySet()) {
            Collection<Object> values = valuesMap.get(key);
            for (Object val : values) {
                session.save(createKeyValue(namespace, key, val));
                count++;
                if (count % getHibernateBatchSize() == 0) {
                    session.flush();
                    session.clear();
                }
            }
        }
        session.getTransaction().commit();
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

From source file:net.minecraftforge.common.ForgeChunkManager.java

static void saveWorld(World world) {
    // only persist persistent worlds
    if (!(world instanceof WorldServer)) {
        return;/*from   ww  w.j  a v  a 2 s  .c  o m*/
    }
    WorldServer worldServer = (WorldServer) world;
    File chunkDir = worldServer.getChunkSaveLocation();
    File chunkLoaderData = new File(chunkDir, "forcedchunks.dat");

    NBTTagCompound forcedChunkData = new NBTTagCompound();
    NBTTagList ticketList = new NBTTagList();
    forcedChunkData.setTag("TicketList", ticketList);

    Multimap<String, Ticket> ticketSet = tickets.get(worldServer);
    if (ticketSet == null)
        return;
    for (String modId : ticketSet.keySet()) {
        NBTTagCompound ticketHolder = new NBTTagCompound();
        ticketList.appendTag(ticketHolder);

        ticketHolder.setString("Owner", modId);
        NBTTagList tickets = new NBTTagList();
        ticketHolder.setTag("Tickets", tickets);

        for (Ticket tick : ticketSet.get(modId)) {
            NBTTagCompound ticket = new NBTTagCompound();
            ticket.setByte("Type", (byte) tick.ticketType.ordinal());
            ticket.setByte("ChunkListDepth", (byte) tick.maxDepth);
            if (tick.isPlayerTicket()) {
                ticket.setString("ModId", tick.modId);
                ticket.setString("Player", tick.player);
            }
            if (tick.modData != null) {
                ticket.setTag("ModData", tick.modData);
            }
            if (tick.ticketType == Type.ENTITY && tick.entity != null
                    && tick.entity.writeToNBTOptional(new NBTTagCompound())) {
                ticket.setInteger("chunkX", MathHelper.floor_double(tick.entity.chunkCoordX));
                ticket.setInteger("chunkZ", MathHelper.floor_double(tick.entity.chunkCoordZ));
                ticket.setLong("PersistentIDMSB", tick.entity.getPersistentID().getMostSignificantBits());
                ticket.setLong("PersistentIDLSB", tick.entity.getPersistentID().getLeastSignificantBits());
                tickets.appendTag(ticket);
            } else if (tick.ticketType != Type.ENTITY) {
                tickets.appendTag(ticket);
            }
        }
    }
    try {
        CompressedStreamTools.write(forcedChunkData, chunkLoaderData);
    } catch (IOException e) {
        FMLLog.log(Level.WARN, e, "Unable to write forced chunk data to %s - chunkloading won't work",
                chunkLoaderData.getAbsolutePath());
        return;
    }
}

From source file:org.richfaces.request.MultipartRequestParser.java

private String getFirstParameterValue(Multimap<String, String> multimap, String key) {
    Collection<String> values = multimap.get(key);

    if (values.isEmpty()) {
        return null;
    }/*from  w  w w  . j ava  2 s .  c  o  m*/

    return Iterables.get(values, 0);
}

From source file:org.sosy_lab.cpachecker.cpa.constraints.refiner.precision.ConstraintBasedConstraintsPrecision.java

private boolean constraintWithSameMeaningExists(final String pFunctionName, final Constraint pConstraint,
        final Multimap<String, Constraint> pTrackedConstraints) {

    if (pTrackedConstraints.containsKey(pFunctionName)) {
        final Collection<Constraint> constraintsOnLocation = pTrackedConstraints.get(pFunctionName);

        for (Constraint c : constraintsOnLocation) {
            if (SymbolicValues.representSameCCodeExpression(c, pConstraint)) {
                return true;
            }/*from   ww w  .  ja v  a  2  s  . c o  m*/
        }
    }

    return false;
}

From source file:uk.ac.ebi.mdk.service.loader.data.ChEBIDataLoader.java

public String getFormula(String accession, Collection<DataValue> values) {

    Set<DataValue> formulae = new HashSet<DataValue>();
    for (DataValue value : values) {
        if (value.type.equals("FORMULA") && !value.value.equals(".")) {
            formulae.add(value);/*from  w w  w.j  a  va 2s.c  o m*/
        }
    }

    if (formulae.isEmpty())
        return "";

    // single entry
    if (formulae.size() == 1) {
        return formulae.iterator().next().value;
    }

    // resolve duplicates
    Multimap<String, DataValue> sourceMap = HashMultimap.create();

    for (DataValue value : formulae) {
        sourceMap.put(value.source, value);
    }

    if (sourceMap.size() != 1 && sourceMap.containsKey("ChEBI")) {
        Collection<DataValue> chebiFormulae = sourceMap.get("ChEBI");
        if (chebiFormulae.size() == 1) {
            return chebiFormulae.iterator().next().value;
        } else if (chebiFormulae.size() == 2) {
            // if there are two from ChEBI, favour the one with the R group
            Iterator<DataValue> it = chebiFormulae.iterator();
            DataValue first = it.next();
            DataValue second = it.next();
            if (first.value.contains("R") && !second.value.contains("R")) {
                return first.value;
            } else if (second.value.contains("R") && !first.value.contains("R")) {
                return second.value;
            }
        }

    }

    LOGGER.warn("Could not resolve single formula for: " + accession + " : " + formulae);

    // just use the first one
    return formulae.iterator().next().value;

}

From source file:org.eclipse.tracecompass.internal.lttng2.kernel.ui.views.vm.vcpuview.VirtualMachineViewEntry.java

/**
 * Get the state intervals for a given thread ID
 *
 * @param threadId/*from  ww w.j av  a  2  s  .  c o  m*/
 *            The thread ID for which to get the intervals
 * @return A collection of intervals for this thread, or {@code null} if no
 *         intervals are available for this thread
 */
public @Nullable Collection<ITmfStateInterval> getThreadIntervals(Integer threadId) {
    final Multimap<Integer, ITmfStateInterval> threadIntervals = fThreadIntervals;
    if (threadIntervals == null) {
        return null;
    }
    return threadIntervals.get(threadId);

}

From source file:io.scigraph.internal.CypherUtil.java

String substituteRelationships(String query, final Multimap<String, Object> valueMap) {
    StrSubstitutor substitutor = new StrSubstitutor(new StrLookup<String>() {
        @Override// w  ww  .  j av a2  s . c  o  m
        public String lookup(String key) {
            Collection<String> resolvedRelationshipTypes = transform(valueMap.get(key),
                    new Function<Object, String>() {
                        @Override
                        public String apply(Object input) {
                            if (input.toString().matches(".*(\\s).*")) {
                                throw new IllegalArgumentException(
                                        "Cypher relationship templates must not contain spaces");
                            }
                            return curieUtil.getIri(input.toString()).or(input.toString());
                        }

                    });
            return on("|").join(resolvedRelationshipTypes);
        }
    });
    return substitutor.replace(query);
}

From source file:com.qcadoo.mes.cmmsMachineParts.states.EventDocumentsService.java

@Transactional(propagation = Propagation.REQUIRES_NEW)
private void createDocuments(final Entity event) {

    EventType eventType = EventType.of(event);

    List<Entity> machinePartsForEvent = event.getHasManyField(eventType.getMachinePartsName());
    if (machinePartsForEvent.isEmpty()) {
        return;//from w  w w. j a  v  a 2s  .  com
    }

    DataDefinition warehouseDD = dataDefinitionService.get(MaterialFlowConstants.PLUGIN_IDENTIFIER,
            MaterialFlowConstants.MODEL_LOCATION);
    Multimap<Long, Entity> groupedMachinePartsForEvent = groupMachinePartsByLocation(machinePartsForEvent);

    boolean resourcesSufficient = true;
    for (Long warehouseId : groupedMachinePartsForEvent.keySet()) {
        Collection<Entity> machinePartsForLocation = groupedMachinePartsForEvent.get(warehouseId);
        List<Entity> machineParts = machinePartsForLocation.stream()
                .map(part -> part.getBelongsToField(MachinePartForEventFields.MACHINE_PART)).distinct()
                .collect(Collectors.toList());
        Entity warehouse = warehouseDD.get(warehouseId);
        Map<Long, BigDecimal> quantitiesInWarehouse = materialFlowResourcesService
                .getQuantitiesForProductsAndLocation(machineParts, warehouse);

        if (!checkIfResourcesAreSufficient(event, quantitiesInWarehouse, machinePartsForLocation, warehouse)) {
            resourcesSufficient = false;
        }
    }
    if (!resourcesSufficient) {
        return;
    }
    for (Long warehouseId : groupedMachinePartsForEvent.keySet()) {
        Collection<Entity> machinePartsForLocation = groupedMachinePartsForEvent.get(warehouseId);

        Entity warehouse = warehouseDD.get(warehouseId);

        Entity document = createDocumentForLocation(event, eventType, warehouse, machinePartsForLocation);
        if (!document.isValid()) {
            event.addGlobalError("cmmsMachineParts.maintenanceEvent.state.documentNotCreated");
            return;
        }
    }

}

From source file:com.ansorgit.plugins.bash.lang.psi.impl.vars.BashVarProcessor.java

private boolean isValidDefinition(BashVarDef varDef, ResolveState resolveState) {
    if (varDef.isCommandLocal()) {
        return false;
    }//from   w  w w  .j a va2  s.  c o  m

    if (!varDef.isStaticAssignmentWord()) {
        return false;
    }

    BashFunctionDef varDefScope = BashPsiUtils.findNextVarDefFunctionDefScope(varDef);
    if (ignoreGlobals && varDefScope == null) {
        return false;
    }

    //first case: the definition is before the start element -> the definition is valid
    //second case: the definition is after the start element:
    //  - if startElement and varDef do NOT share a common scope -> varDef is only valid if it's inside of a function definition, i.e. global
    //  - if startElement and varDef share a scope which different from the PsiFile -> valid if the startElement is inside of a function def
    //this check is only valid if both elements are in the same file

    boolean sameFiles = this.leaveInjectionHost
            ? BashPsiUtils.findFileContext(startElement).equals(BashPsiUtils.findFileContext(varDef))
            : startElement.getContainingFile().equals(varDef.getContainingFile());

    if (sameFiles) {
        int textOffsetVarDef = BashPsiUtils.getFileTextOffset(varDef);
        if (startElementTextOffset >= textOffsetVarDef) {
            return isDefinitionOffsetValid(varDefScope);
        }

        //the found varDef is AFTER the startElement

        if (varDefScope == null) {
            //if varDef is on global level, then it is only valid if startElement is inside of a function definition
            return startElementScope != null;
        }

        //varDef has a valid function def scope AND comes after the start element
        //in this case it is only valid if start element is in a nested function definition inside of varDefScope
        // The found variable definition is defined in a function. If the settings is enabled, i.e. less strict checking, then the variable definition is valid
        // if two var defs are compared then the varDef candidate (which occurs later in the file) is not a possible definition
        if (functionVarDefsAreGlobal && startElementScope != null && !startElementIsVarDef
                && !varDefScope.equals(startElementScope)) {
            return true;
        }

        if (startElementScope != null) {
            return PsiTreeUtil.isAncestor(varDefScope, startElementScope, true);
        }
    } else {
        //working on a definition in an included file (maybe even over several include-steps)
        Multimap<VirtualFile, PsiElement> includedFiles = resolveState.get(visitedIncludeFiles);
        Collection<PsiElement> includeCommands = includedFiles != null
                ? includedFiles.get(varDef.getContainingFile().getVirtualFile())
                : null;

        if (includeCommands == null || includeCommands.isEmpty()) {
            return false;
        }

        PsiElement includeCommand = includeCommands.iterator().next();
        BashFunctionDef includeCommandScope = BashPsiUtils.findNextVarDefFunctionDefScope(includeCommand);

        //now check the offset of the include command
        int startOffset = BashPsiUtils.getFileTextOffset(startElement);
        int endOffset = BashPsiUtils.getFileTextOffset(includeCommand);
        if (startOffset >= endOffset) {
            return isDefinitionOffsetValid(includeCommandScope);
        }

        //the include command comes AFTER the start element
        if (includeCommandScope == null) {
            return BashPsiUtils.findNextVarDefFunctionDefScope(includeCommand) != null;
        }

        if (startElementScope != null) {
            return PsiTreeUtil.isAncestor(varDefScope, includeCommandScope, true);
        }
    }

    return false;
}

From source file:com.google.template.soy.passes.AddHtmlCommentsForDebugPass.java

/** Tries to do simple BFS and mark all callers. */
private void collectCallers(Set<TemplateNode> templatesToRewrite,
        Multimap<TemplateNode, TemplateNode> strictHtmlCallers) {
    Queue<TemplateNode> queue = new ArrayDeque<>();
    queue.addAll(templatesToRewrite);//  w w w  .ja v a 2  s .  com
    while (!queue.isEmpty()) {
        TemplateNode node = queue.poll();
        for (TemplateNode caller : strictHtmlCallers.get(node)) {
            // Only push to queue if caller has not been visited yet.
            if (templatesToRewrite.add(caller)) {
                queue.add(caller);
            }
        }
    }
}