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

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

Introduction

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

Prototype

Set<K> keySet();

Source Link

Document

Returns a view collection of all distinct keys contained in this multimap.

Usage

From source file:com.b2international.snowowl.snomed.datastore.converter.SnomedReferenceSetMemberConverter.java

private void expandReferencedComponent(List<SnomedReferenceSetMember> results) {
    if (expand().containsKey("referencedComponent")) {
        Options expandOptions = expand().get("referencedComponent", Options.class);

        final Multimap<String, SnomedReferenceSetMember> referencedComponentIdToMemberMap = collectReferencedComponentIds(
                results);/*from  w w  w .ja va  2 s .  c  o m*/
        final Multimap<ComponentCategory, String> componentCategoryToIdMap = collectReferencedComponentCategories(
                referencedComponentIdToMemberMap);

        for (ComponentCategory category : componentCategoryToIdMap.keySet()) {
            expandComponentCategory(expandOptions, referencedComponentIdToMemberMap, componentCategoryToIdMap,
                    category);
        }
    }
}

From source file:com.mycompany.swapriori.Generate2LargeItemSets.java

public void generateLargeItemSets(Map<String, Multimap> ObjectInfo, float minSup) {
    List<String> objectSet = new ArrayList(ObjectInfo.keySet());
    //for each Ob1, ob2 in object info list
    for (int i = 0; i < objectSet.size(); i++) {
        for (int j = i + 1; j < objectSet.size(); j++) {
            System.out.println(objectSet.get(i) + " " + objectSet.get(j));

            //get list of predicate and corresponding subjects
            Multimap<String, String> predicateSubject1 = ObjectInfo.get(objectSet.get(i));
            Multimap<String, String> predicateSubject2 = ObjectInfo.get(objectSet.get(j));
            System.out.println(predicateSubject1);
            System.out.println(predicateSubject2);

            //get list of predicates to get subjects from Multimap
            List<String> predicateKeySet1 = new ArrayList(predicateSubject1.keySet());
            List<String> predicateKeySet2 = new ArrayList(predicateSubject2.keySet());

            //for each r1 in ob1
            for (int i1 = 0; i < predicateKeySet1.size(); i1++) {
                // for each r2 in ob2
                for (int j1 = 0; j < predicateKeySet2.size(); j1++) {
                    //get SS1 and SS2
                    Set<String> subjectList1 = new LinkedHashSet(
                            predicateSubject1.get(predicateKeySet1.get(i1)));
                    Set<String> subjectList2 = new LinkedHashSet(
                            predicateSubject2.get(predicateKeySet2.get(j1)));

                    //get intersection of subject lists
                    subjectList1.retainAll(subjectList2);

                    //get count of intersections
                    System.out.println(subjectList1.size());
                    int intersectionCount = subjectList1.size();
                }//from  ww w  .ja  va2s . co  m
            }

        }
    }
}

From source file:org.eclipse.viatra.transformation.runtime.emf.changemonitor.ChangeMonitor.java

/**
 * Public method used for adding new rules to the monitor. This method can be used both before and after monitoring
 * has been started./*ww w  .java 2s .  co m*/
 * 
 * @param rule
 *            The rule to be added to the monitor
 */
public void addRule(RuleSpecification<IPatternMatch> rule) {
    rules.add(rule);
    Multimap<ActivationState, Job<IPatternMatch>> jobs = rule.getJobs();
    if (started) {
        executionSchema.addRule(rule);
    }
    for (ActivationState state : jobs.keySet()) {
        for (Job<?> job : jobs.get(state)) {
            if (started) {
                EnableJob<?> enableJob = (EnableJob<?>) job;
                enableJob.setEnabled(true);
            } else {
                allJobs.add(job);
            }
        }
    }
}

From source file:org.summer.dsl.xbase.ui.imports.InteractiveUnresolvedTypeResolver.java

public void resolve(TypeUsages typeUsages, XtextResource resource) {
    if (typeUsages.getUnresolvedTypeUsages().isEmpty() || resource == null)
        return;//from  w ww  .jav a2  s.  c o  m
    Multimap<String, TypeUsage> name2usage = LinkedHashMultimap.create();
    for (TypeUsage unresolved : typeUsages.getUnresolvedTypeUsages()) {
        String text = unresolved.getUsedTypeName();
        text = nameValueConverter.toValue(text, null);
        name2usage.put(text, unresolved);
    }
    for (String name : name2usage.keySet()) {
        Iterable<TypeUsage> usages = name2usage.get(name);
        JvmDeclaredType resolvedType = resolve(name, usages, resource);
        if (resolvedType != null) {
            for (TypeUsage usage : usages)
                typeUsages.addTypeUsage(resolvedType, usage.getSuffix(), usage.getTextRegion(),
                        usage.getContext());
        }
    }
}

From source file:org.eclipse.xtext.ui.refactoring.impl.AbstractReferenceUpdater.java

protected void createClusteredReferenceUpdates(ElementRenameArguments elementRenameArguments,
        Multimap<URI, IReferenceDescription> resource2references, ResourceSet resourceSet,
        IRefactoringUpdateAcceptor updateAcceptor, StatusWrapper status, IProgressMonitor monitor) {
    SubMonitor progress = SubMonitor.convert(monitor, resource2references.keySet().size() + 1);
    if (loadTargetResources(resourceSet, elementRenameArguments, status, progress.newChild(1))) {
        if (getClusterSize() > 0) {
            Set<Resource> targetResources = newHashSet(resourceSet.getResources());
            Multimap<URI, IReferenceDescription> cluster = HashMultimap.create();
            SubMonitor clusterMonitor = progress.newChild(1);
            for (URI referringResourceURI : resource2references.keySet()) {
                cluster.putAll(referringResourceURI, resource2references.get(referringResourceURI));
                if (cluster.keySet().size() == getClusterSize()) {
                    unloadNonTargetResources(resourceSet, targetResources);
                    createReferenceUpdatesForCluster(elementRenameArguments, cluster, resourceSet,
                            updateAcceptor, status, clusterMonitor);
                    cluster.clear();/*  w  w  w . ja  v a  2  s  .co m*/
                }
            }
            if (!cluster.isEmpty()) {
                unloadNonTargetResources(resourceSet, targetResources);
                createReferenceUpdatesForCluster(elementRenameArguments, cluster, resourceSet, updateAcceptor,
                        status, clusterMonitor);
            }
        } else {
            createReferenceUpdatesForCluster(elementRenameArguments, resource2references, resourceSet,
                    updateAcceptor, status, progress.newChild(resource2references.keySet().size()));
        }
    }
}

From source file:carskit.data.processor.DataTransformer.java

private void PublishNewRatingFiles(String outputfolder, Multimap<String, String> conditions,
        HashMap<String, HashMap<String, String>> newlines, boolean isLoose) throws Exception {
    // add missing values to the condition sets
    for (String dim : conditions.keySet()) {
        conditions.put(dim, "na");
    }//  ww  w.j a  va2  s  .com

    // create header
    StringBuilder headerBuilder = new StringBuilder();
    headerBuilder.append("user,item,rating");
    int start = 0;
    for (String dim : conditions.keySet()) {
        Collection<String> conds = conditions.get(dim);
        for (String cond : conds) {
            if (headerBuilder.length() > 0)
                headerBuilder.append(",");
            headerBuilder.append(dim + ":" + cond);
        }
    }
    String header = headerBuilder.toString();

    BufferedWriter bw = FileIO.getWriter(outputfolder + "ratings_binary.txt");
    bw.write(header + "\n");
    bw.flush();

    // start rewrite rating records
    for (String key : newlines.keySet()) {
        HashMap<String, String> ratingcontext = newlines.get(key);
        StringBuilder conditionBuilder = new StringBuilder();
        for (String dim : conditions.keySet()) {
            boolean isNA = false;
            boolean isCompleted = false;
            Collection<String> conds = conditions.get(dim);

            String dimCondition = ratingcontext.get(dim);
            if (dimCondition == null) {// 1st NA situation: because there is no such dim in this rating profile
                isNA = true;
            } else if (dimCondition.equals("na")) // 2nd NA situation: it is already tagged with NA in this dim
            {
                isNA = true;
            }

            for (String cond : conds) {
                if (conditionBuilder.length() > 0)
                    conditionBuilder.append(",");
                if (isLoose) {
                    if (isNA) {
                        if (cond.equals("na")) {
                            conditionBuilder.append("1");
                            isCompleted = true;
                        } else
                            conditionBuilder.append("0");
                    } else {
                        if (isCompleted)
                            conditionBuilder.append("0");
                        else {
                            if (cond.equals(dimCondition)) {
                                conditionBuilder.append("1");
                                isCompleted = true; // have found one condition for this dimension, all others are 0
                            } else
                                conditionBuilder.append("0");
                        }
                    }
                } else {
                    if (dimCondition.equals(cond))
                        conditionBuilder.append("1");
                    else
                        conditionBuilder.append("0");
                }
            }

        }
        String[] skey = key.split(",", -1); // when original format is compact, the key is whole line.
        if (skey.length > 3)
            key = skey[0].trim().toLowerCase() + "," + skey[1].trim().toLowerCase() + ","
                    + skey[2].trim().toLowerCase();

        bw.write(key + "," + conditionBuilder.toString() + "\n");
        bw.flush();
    }
    bw.close();
}

From source file:org.eclipse.xtext.xbase.ui.imports.InteractiveUnresolvedTypeResolver.java

@Override
public void resolve(TypeUsages typeUsages, XtextResource resource) {
    if (typeUsages.getUnresolvedTypeUsages().isEmpty() || resource == null)
        return;/*  w ww .  j av  a2 s . co m*/
    Multimap<String, TypeUsage> name2usage = LinkedHashMultimap.create();
    for (TypeUsage unresolved : typeUsages.getUnresolvedTypeUsages()) {
        String text = unresolved.getUsedTypeName();
        text = nameValueConverter.toValue(text, null);
        name2usage.put(text, unresolved);
    }
    for (String name : name2usage.keySet()) {
        Iterable<TypeUsage> usages = name2usage.get(name);
        JvmDeclaredType resolvedType = resolve(name, usages, resource);
        if (resolvedType != null) {
            for (TypeUsage usage : usages)
                typeUsages.addTypeUsage(resolvedType, usage.getSuffix(), usage.getTextRegion(),
                        usage.getContext());
        }
    }
}

From source file:org.apache.sentry.core.common.utils.PolicyFile.java

private String getSection(String name, Multimap<String, String> mapping) {
    if (mapping.isEmpty()) {
        return "";
    }//  ww w  . j av  a  2 s. c  o m
    Joiner kvJoiner = Joiner.on(" = ");
    Joiner itemJoiner = Joiner.on(" , ");
    List<String> lines = Lists.newArrayList();
    lines.add("[" + name + "]");
    for (String key : mapping.keySet()) {
        lines.add(kvJoiner.join(key, itemJoiner.join(mapping.get(key))));
    }
    return Joiner.on(NL).join(lines);
}

From source file:com.b2international.snowowl.snomed.importer.rf2.terminology.ComponentLookup.java

private LongValueMap<String> getStorageKeys(final Collection<String> componentIds) throws IOException {
    return index.read(editingContext.getBranch(), new RevisionIndexRead<LongValueMap<String>>() {
        @Override//from   w w  w  .  j  ava 2s . c om
        public LongValueMap<String> execute(RevisionSearcher index) throws IOException {
            final LongValueMap<String> map = PrimitiveMaps
                    .newObjectKeyLongOpenHashMapWithExpectedSize(componentIds.size());
            // index componentIds by their category
            final Multimap<Class<? extends SnomedDocument>, String> idsByType = Multimaps.index(componentIds,
                    id -> SnomedDocument.getType(SnomedIdentifiers.getComponentCategory(id)));
            for (Class<? extends SnomedDocument> type : idsByType.keySet()) {
                // execute queries for each type and based on the current clazz extract either refset or concept storage keys
                final Query<? extends SnomedDocument> query = Query.select(type)
                        .where(SnomedDocument.Expressions.ids(componentIds)).limit(componentIds.size()).build();
                final Hits<? extends SnomedDocument> hits = index.search(query);
                for (SnomedDocument doc : hits) {
                    if (SnomedRefSet.class.isAssignableFrom(clazz)) {
                        map.put(doc.getId(), ((SnomedConceptDocument) doc).getRefSetStorageKey());
                    } else {
                        map.put(doc.getId(), doc.getStorageKey());
                    }
                }
            }
            return map;
        }
    });
}

From source file:org.robotframework.ide.eclipse.main.plugin.project.build.validation.KeywordSettingsValidator.java

private void reportDuplicatedArguments() {
    final String fileName = validationContext.getFile().getName();

    final Multimap<String, RobotToken> arguments = extractArgumentVariables(keyword, new VariableExtractor(),
            fileName);/*from   ww w  .  ja  v a  2  s . c om*/

    for (final String arg : arguments.keySet()) {
        final Collection<RobotToken> tokens = arguments.get(arg);
        if (tokens.size() > 1) {
            for (final RobotToken token : tokens) {
                final RobotProblem problem = RobotProblem.causedBy(KeywordsProblem.ARGUMENT_DEFINED_TWICE)
                        .formatMessageWith(token.getText());
                reporter.handleProblem(problem, validationContext.getFile(), token);
            }
        }
    }
}