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

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

Introduction

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

Prototype

boolean containsKey(@Nullable Object key);

Source Link

Document

Returns true if this multimap contains at least one key-value pair with the key key .

Usage

From source file:de.esukom.decoit.ifmapclient.iptables.PollResultChecker.java

/**
 * check if passed in entry from poll-result-meta-data matches an "allowance" or an enforcement
 * filter-strings from enforcement.properties
 * //from  www.j ava2 s .c  om
 * @param filterStrings map of rules to check against
 * @param resultPropertyValue the property of the entry to check
 * @param resultFilterValue value to compare to entry-content
 * @param checkType type of check to perform (contains/matches)
 * 
 * @return true, if passed in result-filter-value is contained or matched with entry inside
 *         filter-string--map
 */
public boolean checkPollResultForIPTablesStringRules(Multimap<String, String> filterStrings,
        String resultPropertyValue, String resultFilterValue, byte checkType, byte resultType) {

    IfMapClient.LOGGER.fine("checking poll result for string rules...");
    IfMapClient.LOGGER.fine("resultPropertyValue: " + resultPropertyValue);
    IfMapClient.LOGGER.fine("resultFilterValue: " + resultFilterValue);
    IfMapClient.LOGGER.fine("filterStrings: " + filterStrings.toString());

    // contains-match
    if (checkType == RULECHECK_TYPE_CONTAINS) {
        if (resultType == RESULTCHECK_TYPE_SEARCHRESULT) {
            if (filterStrings.containsKey("role_" + resultPropertyValue)) {
                return checkStringAttributeContainsValue(filterStrings, "role_" + resultPropertyValue,
                        resultFilterValue);
            } else if (filterStrings.containsKey("!role_" + resultPropertyValue)) {
                return checkStringAttributeContainsValue(filterStrings, "!role_" + resultPropertyValue,
                        resultFilterValue);
            } else if (filterStrings.containsKey("capability_" + resultPropertyValue)) {
                return checkStringAttributeContainsValue(filterStrings, "capability_" + resultPropertyValue,
                        resultFilterValue);
            } else if (filterStrings.containsKey("!capability_" + resultPropertyValue)) {
                return checkStringAttributeContainsValue(filterStrings, "!capability_" + resultPropertyValue,
                        resultFilterValue);
            } else if (filterStrings.containsKey("device-characteristic_" + resultPropertyValue)) {
                return checkStringAttributeContainsValue(filterStrings,
                        "device-characteristic_" + resultPropertyValue, resultFilterValue);
            } else if (filterStrings.containsKey("!device-characteristic_" + resultPropertyValue)) {
                return checkStringAttributeContainsValue(filterStrings,
                        "!device-characteristic_" + resultPropertyValue, resultFilterValue);
            } else if (filterStrings.containsKey("access-request-ip_" + resultPropertyValue)) {
                return checkStringAttributeContainsValue(filterStrings,
                        "access-request-ip_" + resultPropertyValue, resultFilterValue);
            } else if (filterStrings.containsKey("!access-request-ip_" + resultPropertyValue)) {
                return checkStringAttributeContainsValue(filterStrings,
                        "!access-request-ip_" + resultPropertyValue, resultFilterValue);
            }

        } else {
            if (filterStrings.containsKey(resultPropertyValue)) {
                return checkStringAttributeContainsValue(filterStrings, resultPropertyValue, resultFilterValue);
            }
        }

    }

    // match-match ;-)
    else /* if (checkType == RULECHECK_TYPE_MATCHES) */ {
        if (resultType == RESULTCHECK_TYPE_SEARCHRESULT) {
            if (filterStrings.containsKey("role_" + resultPropertyValue)) {
                return checkStringAttributeMatchesValue(filterStrings, "role_" + resultPropertyValue,
                        resultFilterValue);
            } else if (filterStrings.containsKey("!role_" + resultPropertyValue)) {
                return checkStringAttributeMatchesValue(filterStrings, "!role_" + resultPropertyValue,
                        resultFilterValue);
            } else if (filterStrings.containsKey("capability_" + resultPropertyValue)) {
                return checkStringAttributeMatchesValue(filterStrings, "capability_" + resultPropertyValue,
                        resultFilterValue);
            } else if (filterStrings.containsKey("!capability_" + resultPropertyValue)) {
                return checkStringAttributeMatchesValue(filterStrings, "!capability_" + resultPropertyValue,
                        resultFilterValue);
            } else if (filterStrings.containsKey("device-characteristic_" + resultPropertyValue)) {
                return checkStringAttributeMatchesValue(filterStrings,
                        "device-characteristic_" + resultPropertyValue, resultFilterValue);
            } else if (filterStrings.containsKey("!device-characteristic_" + resultPropertyValue)) {
                return checkStringAttributeMatchesValue(filterStrings,
                        "!device-characteristic_" + resultPropertyValue, resultFilterValue);
            } else if (filterStrings.containsKey("access-request-ip_" + resultPropertyValue)) {
                return checkStringAttributeMatchesValue(filterStrings,
                        "access-request-ip_" + resultPropertyValue, resultFilterValue);
            } else if (filterStrings.containsKey("!access-request-ip_" + resultPropertyValue)) {
                return checkStringAttributeMatchesValue(filterStrings,
                        "!access-request-ip_" + resultPropertyValue, resultFilterValue);
            }
        } else {
            return checkStringAttributeMatchesValue(filterStrings, resultPropertyValue, resultFilterValue);
        }
    }

    return false;
}

From source file:com.android.tools.idea.wizard.ModuleListModel.java

private Multimap<ModuleToImport, ModuleToImport> computeRequiredModules(Set<ModuleToImport> modules) {
    Map<String, ModuleToImport> namesToModules = Maps.newHashMapWithExpectedSize(modules.size());
    // We only care about modules we are actually going to import.
    for (ModuleToImport module : modules) {
        namesToModules.put(module.name, module);
    }//from   www .  j  av a  2  s.  c  o  m
    Multimap<ModuleToImport, ModuleToImport> requiredModules = LinkedListMultimap.create();
    Queue<ModuleToImport> queue = Lists.newLinkedList();

    for (ModuleToImport module : modules) {
        if (Objects.equal(module, myPrimaryModule) || !isUnselected(module, false)) {
            queue.add(module);
        }
    }
    while (!queue.isEmpty()) {
        ModuleToImport moduleToImport = queue.remove();
        for (ModuleToImport dep : Iterables.transform(moduleToImport.getDependencies(),
                Functions.forMap(namesToModules, null))) {
            if (dep != null) {
                if (!requiredModules.containsKey(dep)) {
                    queue.add(dep);
                }
                requiredModules.put(dep, moduleToImport);
            }
        }
    }
    return requiredModules;
}

From source file:org.opennms.features.topology.plugins.topo.linkd.internal.OspfLinkStatusProvider.java

@Override
protected List<EdgeAlarmStatusSummary> getEdgeAlarmSummaries(List<Integer> linkIds) {
    org.opennms.core.criteria.Criteria criteria = new org.opennms.core.criteria.Criteria(OspfLink.class);
    criteria.addRestriction(new InRestriction("id", linkIds));

    List<OspfLink> links = getOspfLinkDao().findMatching(criteria);
    Multimap<String, EdgeAlarmStatusSummary> summaryMap = HashMultimap.create();
    for (OspfLink sourceLink : links) {
        OnmsNode sourceNode = sourceLink.getNode();
        for (OspfLink targetLink : links) {
            boolean ipAddrCheck = sourceLink.getOspfRemIpAddr().equals(targetLink.getOspfIpAddr())
                    && targetLink.getOspfRemIpAddr().equals(sourceLink.getOspfIpAddr());
            if (ipAddrCheck) {
                summaryMap.put(sourceNode.getNodeId() + ":" + sourceLink.getOspfIfIndex(),
                        new EdgeAlarmStatusSummary(sourceLink.getId(), targetLink.getId(), null));
            }//  ww  w .  j a  v a2s  . c  o  m
        }
    }

    List<OnmsAlarm> alarms = getLinkDownAlarms();

    for (OnmsAlarm alarm : alarms) {
        String key = alarm.getNodeId() + ":" + alarm.getIfIndex();
        if (summaryMap.containsKey(key)) {

            Collection<EdgeAlarmStatusSummary> summaries = summaryMap.get(key);
            for (EdgeAlarmStatusSummary summary : summaries) {
                summary.setEventUEI(alarm.getUei());
            }

        }

    }

    return new ArrayList<EdgeAlarmStatusSummary>(summaryMap.values());

}

From source file:uk.ac.ebi.mdk.apps.tool.SuggestExchangeMetabolites.java

@Override
public void process() {

    System.out.print("Reading reconstructions...");
    Reconstruction input = read(getFile("input"));
    Reconstruction reference = read(getFile("reference"));
    System.out.println("done");

    // find compounds which are exchange in the 'reference' and list
    // - those which are exchanged and present the input
    // - those which are terminal in the input
    Multimap<Metabolite, MetabolicReaction> exchanged = exchanged(reference);
    Multimap<Long, Metabolite> index = index(exchanged.keySet());

    BiMap<UUID, Integer> metaboliteIdx = HashBiMap.create(input.metabolome().size());
    int i = 0;//from   ww w. j a v  a 2 s  . c  o m
    for (Metabolite m : input.metabolome())
        metaboliteIdx.put(m.uuid(), i++);
    int[] occurences = new int[input.metabolome().size()];

    for (MetabolicReaction rxn : input.reactome()) {
        for (MetabolicParticipant p : rxn.getParticipants()) {
            occurences[metaboliteIdx.get(p.getMolecule().uuid())]++;
        }
    }

    CSVWriter csv = new CSVWriter(new OutputStreamWriter(System.out), ',', '"');

    for (final Metabolite metabolite : input.metabolome()) {
        for (ChemicalStructure structure : metabolite.getStructures()) {
            long hashCode = generator.generate(structure.getStructure());
            if (index.containsKey(hashCode)) {
                for (Metabolite refMetabolite : index.get(hashCode)) {
                    for (MetabolicReaction rxn : exchanged.get(refMetabolite)) {
                        csv.writeNext(new String[] { metabolite.toString(),
                                Integer.toString(occurences[metaboliteIdx.get(metabolite.uuid())]),
                                rxn.toString() });

                    }
                }
            }
        }
    }

    try {
        csv.flush();
        csv.close();
    } catch (IOException e) {
        System.err.println(e.getMessage());
    }
}

From source file:old.MetaboliteComparison.java

/**
 * Generates a comparison table//from  w  ww  .  j a  va2s .  c o  m
 * @param type
 * @return
 */
public JTable getComparisconTable(final TableData type) {

    JTable table = new JTable();

    Reconstruction[] recons = comparison.getReconstructions();

    Map<Long, Multimap<Reconstruction, Metabolite>> map = new HashMap<Long, Multimap<Reconstruction, Metabolite>>();

    for (int i = 0; i < recons.length; i++) {
        Reconstruction reconstruction = recons[i];
        for (Entry<Metabolite, Long> e : comparison.getMoleculeHashMap(reconstruction).entrySet()) {

            Long key = e.getValue();
            if (!map.containsKey(key)) {
                Multimap<Reconstruction, Metabolite> sub = ArrayListMultimap.create();
                map.put(key, sub);
            }
            map.get(key).put(reconstruction, e.getKey());
        }
    }

    List<IAtomContainer> structures = new ArrayList();

    Object[][] data = new Object[map.keySet().size()][recons.length];
    int i = 0;
    for (Entry<Long, Multimap<Reconstruction, Metabolite>> e : map.entrySet()) {
        Long key = e.getKey();
        Multimap<Reconstruction, Metabolite> sub = e.getValue();
        for (int j = 0; j < recons.length; j++) {

            Reconstruction recon = recons[j];

            switch (type) {

            case PRESENCE:
                data[i][j] = sub.containsKey(recon) ? "x" : "";
                break;

            case OCCURANCE:
                data[i][j] = sub.containsKey(recon) ? sub.get(recon).size() : 0;
                break;

            case NAME:

                List<String> names = new ArrayList();
                if (sub.containsKey(recon)) {
                    for (Metabolite m : sub.get(recon)) {
                        names.add(m.getName());
                    }
                }

                data[i][j] = names;
                break;

            case ABBREVIATION:

                List<String> abbrv = new ArrayList();
                if (sub.containsKey(recon)) {
                    for (Metabolite m : sub.get(recon)) {
                        abbrv.add(m.getAbbreviation());
                    }
                }

                data[i][j] = abbrv;
                break;

            case STRUCTURE:

                List<AtomContainerAnnotation> structure = new ArrayList();
                if (sub.containsKey(recon)) {
                    for (Metabolite m : sub.get(recon)) {
                        if (m.hasStructure()) {
                            Collection<AtomContainerAnnotation> collection = m
                                    .getAnnotationsExtending(AtomContainerAnnotation.class);
                            if (!collection.isEmpty()) {
                                structure.add(collection.iterator().next());
                            }
                        }
                    }
                }

                data[i][j] = structure;
                break;
            }

        }
        i++;
    }

    DefaultTableModel model = new DefaultTableModel(data, recons) {

        @Override
        public Class<?> getColumnClass(int columnIndex) {
            switch (type) {
            case STRUCTURE:
                return AtomContainerAnnotation.class;
            case NAME:
                return List.class;
            case ABBREVIATION:
                return List.class;
            default:
                return Object.class;
            }
        }
    };
    table.setModel(model);
    table.setDefaultRenderer(List.class, new AnnotationCellRenderer());
    if (type == TableData.STRUCTURE) {
        table.setDefaultRenderer(AtomContainerAnnotation.class, new ChemicalStructureRenderer());
        table.setRowHeight(64);
    }

    return table;

}

From source file:io.scigraph.services.jersey.dynamic.CypherInflector.java

@AddCuries
@Override//from   w ww  . j a  v a2s . c om
public Response apply(ContainerRequestContext context) {
    logger.fine("Serving dynamic request");
    Multimap<String, Object> paramMap = MultivaluedMapUtils.merge(context.getUriInfo());
    paramMap = resolveCuries(paramMap);
    try (Transaction tx = graphDb.beginTx()) {
        long start = System.currentTimeMillis();
        start = System.currentTimeMillis();
        Result result = cypherUtil.execute(config.getQuery(), paramMap);
        logger.fine((System.currentTimeMillis() - start) + " to execute query");
        start = System.currentTimeMillis();
        TinkerGraph graph = TinkerGraphUtil.resultToGraph(result);
        logger.fine((System.currentTimeMillis() - start) + " to convert to graph");
        start = System.currentTimeMillis();
        for (String key : aspectMap.keySet()) {
            if ("true".equals(getFirst(paramMap.get(key), "false"))) {
                aspectMap.get(key).invoke(graph);
            }
        }
        if (paramMap.containsKey("project")) {
            @SuppressWarnings("unchecked")
            Collection<String> projection = (Collection<String>) (Collection<?>) paramMap.get("project");
            TinkerGraphUtil.project(graph, projection);
        }
        ArrayPropertyTransformer.transform(graph);
        tx.success();
        return Response.ok(graph).cacheControl(config.getCacheControl()).build();
    }
}

From source file:org.aksw.simba.bengal.triple2nl.DocumentGenerator.java

/**
 * @param documentTriples/*from   w  ww .j  a v a  2  s  .  c o m*/
 *            the set of triples
 * @param subject2Triples
 *            a map that contains for each node the triples in which it
 *            occurs as subject
 */
private Map<Node, Collection<Triple>> sort(Set<Triple> documentTriples,
        Map<Node, Collection<Triple>> subject2Triples) {
    Map<Node, Collection<Triple>> sortedTriples = new LinkedHashMap<>();
    // we can order by occurrence, i.e. which subjects do not occur in
    // object position
    // for each subject we check how often they occur in subject/object
    // position
    Multimap<Node, Node> outgoing = HashMultimap.create();
    Multimap<Node, Node> incoming = HashMultimap.create();
    for (Node subject : subject2Triples.keySet()) {
        for (Triple triple : documentTriples) {
            if (triple.subjectMatches(subject)) {
                outgoing.put(subject, triple.getObject());
            } else if (triple.objectMatches(subject)) {
                incoming.put(subject, triple.getSubject());
            }
        }
    }
    // prefer subjects that do not occur in object position first
    for (Iterator<Entry<Node, Collection<Triple>>> iterator = subject2Triples.entrySet().iterator(); iterator
            .hasNext();) {
        Entry<Node, Collection<Triple>> entry = iterator.next();
        Node subject = entry.getKey();
        if (!incoming.containsKey(subject)) {
            sortedTriples.put(subject, new HashSet<>(entry.getValue()));
            iterator.remove();
        }
    }
    // add the rest
    sortedTriples.putAll(subject2Triples);

    // TODO order by triple count

    // TODO order by prominence

    return sortedTriples;
}

From source file:uk.ac.ebi.mdk.apps.tool.SummariseReferences.java

public void summarise(File in, File out) throws ClassNotFoundException, IOException {

    boolean chemicalOnly = has("c");

    Reconstruction reconstruction = ReconstructionIOHelper.read(in);

    File summaryFile = new File(new File(out, "summary"), reconstruction.getAccession() + ".tsv");
    File chebiFile = new File(new File(out, "chebi"), reconstruction.getAccession() + ".tsv");
    File nonChEBIFile = new File(new File(out, "other"), reconstruction.getAccession() + ".tsv");
    File noneFile = new File(new File(out, "unreferenced"), reconstruction.getAccession() + ".tsv");

    // number of reactions/metabolites
    int n = reconstruction.getMetabolome().size();
    int m = reconstruction.getReactome().size();

    Multimap<Identifier, Identifier> chebi = HashMultimap.create();
    Multimap<Identifier, Identifier> nonChebi = HashMultimap.create();
    Map<Identifier, String> unreferenced = new HashMap<Identifier, String>();
    Set<String> types = new HashSet<String>();

    for (Metabolite metabolite : reconstruction.getMetabolome()) {

        Collection<CrossReference> xrefs = metabolite.getAnnotationsExtending(CrossReference.class);

        for (CrossReference xref : xrefs) {

            Identifier id = xref.getIdentifier();

            types.add(id.getShortDescription());

            if (!chemicalOnly || id instanceof ChemicalIdentifier) {
                if (id instanceof ChEBIIdentifier) {
                    chebi.put(metabolite.getIdentifier(), id);
                } else {
                    nonChebi.put(metabolite.getIdentifier(), id);
                }//from w w w  .j av  a  2s.  co m
            }

        }

        if (!nonChebi.containsKey(metabolite.getIdentifier())
                && !chebi.containsKey(metabolite.getIdentifier())) {
            unreferenced.put(metabolite.getIdentifier(), metabolite.getName());
        }

    }

    // output
    out.mkdirs();
    summaryFile.getParentFile().mkdirs();
    chebiFile.getParentFile().mkdirs();
    nonChEBIFile.getParentFile().mkdirs();
    noneFile.getParentFile().mkdirs();

    // summary

    CSVWriter summaryTSV = new CSVWriter(new FileWriter(summaryFile), '\t', '\0');

    summaryTSV.writeNext(new String[] { reconstruction.getAccession(), Integer.toString(n), Integer.toString(m),
            Integer.toString(chebi.keySet().size()), Integer.toString(nonChebi.keySet().size()),
            Integer.toString(unreferenced.size()), Joiner.on(", ").join(types) });

    summaryTSV.close();

    // chebi references

    CSVWriter chebiTSV = new CSVWriter(new FileWriter(chebiFile), '\t', '\0');
    chebiTSV.writeNext(new String[] { "query.accession", "xref.accession", "xref.resource", "xref.mir" });
    for (Map.Entry<Identifier, Identifier> e : chebi.entries()) {
        chebiTSV.writeNext(new String[] { e.getKey().getAccession(), e.getValue().getAccession(),
                e.getValue().getResource().getName(), ((MIRIAMEntry) e.getValue().getResource()).getId() });
    }
    chebiTSV.close();

    // all chemical id references

    CSVWriter chemicalTSV = new CSVWriter(new FileWriter(nonChEBIFile), '\t', '\0');
    chemicalTSV.writeNext(
            new String[] { "query.accession", "query.name", "xref.accession", "xref.resource", "xref.mir" });
    for (Map.Entry<Identifier, Identifier> e : nonChebi.entries()) {
        chemicalTSV.writeNext(new String[] { e.getKey().getAccession(),
                reconstruction.getMetabolome().ofIdentifier(e.getKey()).iterator().next().getName(),
                e.getValue().getAccession(), e.getValue().getResource().getName(),
                ((MIRIAMEntry) e.getValue().getResource()).getId() });
    }
    chemicalTSV.close();

    // no references

    CSVWriter noneTSV = new CSVWriter(new FileWriter(noneFile), '\t', '\0');
    for (Map.Entry<Identifier, String> e : unreferenced.entrySet()) {
        noneTSV.writeNext(new String[] { e.getKey().getAccession(), e.getValue(), });
    }
    noneTSV.close();

}

From source file:org.opennms.features.topology.plugins.topo.linkd.internal.IsIsLinkStatusProvider.java

@Override
protected List<EdgeAlarmStatusSummary> getEdgeAlarmSummaries(List<Integer> linkIds) {
    Criteria criteria = new Criteria(IsIsLink.class);
    criteria.addRestriction(new InRestriction("id", linkIds));

    List<IsIsLink> links = getIsisLinkDao().findMatching(criteria);
    Multimap<String, EdgeAlarmStatusSummary> summaryMap = HashMultimap.create();
    for (IsIsLink sourceLink : links) {
        OnmsNode sourceNode = sourceLink.getNode();
        IsIsElement sourceElement = sourceNode.getIsisElement();
        for (IsIsLink targetLink : links) {
            boolean isisAdjIndexCheck = sourceLink.getIsisISAdjIndex() == targetLink.getIsisISAdjIndex();
            boolean isisSysIdCheck = targetLink.getIsisISAdjNeighSysID().equals(sourceElement.getIsisSysID());
            if (isisAdjIndexCheck && isisSysIdCheck) {
                summaryMap.put(sourceNode.getNodeId() + ":" + sourceLink.getIsisCircIfIndex(),
                        new EdgeAlarmStatusSummary(sourceLink.getId(), targetLink.getId(), null));
            }/*from  w  w  w.j a  va 2 s . co m*/
        }
    }

    List<OnmsAlarm> alarms = getLinkDownAlarms();
    for (OnmsAlarm alarm : alarms) {
        String key = alarm.getNodeId() + ":" + alarm.getIfIndex();
        if (summaryMap.containsKey(key)) {
            Collection<EdgeAlarmStatusSummary> summaries = summaryMap.get(key);
            for (EdgeAlarmStatusSummary summary : summaries) {
                summary.setEventUEI(alarm.getUei());
            }

        }
    }
    return new ArrayList<EdgeAlarmStatusSummary>(summaryMap.values());
}

From source file:eu.project.ttc.engines.morpho.PrefixSplitter.java

@Override
public void collectionProcessComplete() throws AnalysisEngineProcessException {
    LOGGER.info("Starting {} for TermIndex {}", TASK_NAME, termIndexResource.getTermIndex().getName());
    Multimap<String, Term> lemmaIndex = HashMultimap.create();
    int nb = 0;//from w  w  w .  jav a 2s. c  om
    String prefixExtension, lemma, pref;
    for (Term swt : termIndexResource.getTermIndex().getTerms()) {
        if (!swt.isSingleWord())
            continue;
        else {
            lemmaIndex.put(swt.getLemma(), swt);
        }
    }
    for (Term swt : termIndexResource.getTermIndex().getTerms()) {
        if (!swt.isSingleWord())
            continue;

        Word word = swt.getWords().get(0).getWord();
        lemma = word.getLemma();
        pref = prefixTree.getPrefix(lemma);
        if (pref != null && pref.length() < lemma.length()) {
            prefixExtension = lemma.substring(pref.length(), lemma.length());
            if (LOGGER.isTraceEnabled())
                LOGGER.trace("Found prefix: {} for word {}", pref, lemma);
            if (checkIfMorphoExtensionInCorpus) {
                if (!lemmaIndex.containsKey(prefixExtension)) {
                    if (LOGGER.isTraceEnabled())
                        LOGGER.trace(
                                "Prefix extension: {} for word {} is not found in corpus. Aborting composition for this word.",
                                prefixExtension, lemma);
                    continue;
                } else {
                    for (Term target : lemmaIndex.get(prefixExtension)) {
                        watch(swt, target);
                        swt.addTermVariation(target, VariationType.IS_PREFIX_OF,
                                TermSuiteConstants.EMPTY_STRING);
                    }
                }
            }
            nb++;
        }
    }
    LOGGER.debug("Number of words with prefix composition: {} out of {}", nb,
            termIndexResource.getTermIndex().getWords().size());
}