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:fr.ujm.tse.lt2c.satin.rules.run.RunPRP_SPO1.java

@Override
protected int process(final TripleStore ts1, final TripleStore ts2, final Collection<Triple> outputTriples) {

    final long subPropertyOf = AbstractDictionary.subPropertyOf;

    final int loops = 0;

    final Multimap<Long, Long> subPropertyOfMultiMap = ts1.getMultiMapForPredicate(subPropertyOf);
    if (subPropertyOfMultiMap != null && !subPropertyOfMultiMap.isEmpty()) {

        final HashMap<Long, Collection<Triple>> cachePredicates = new HashMap<>();

        for (final Long p1 : subPropertyOfMultiMap.keySet()) {

            Collection<Triple> matchingTriples;
            if (!cachePredicates.containsKey(p1)) {
                matchingTriples = ts2.getbyPredicate(p1);
                cachePredicates.put(p1, matchingTriples);
            } else {
                matchingTriples = cachePredicates.get(p1);
            }/*  www .ja  v  a2 s .  co m*/

            for (final Triple triple : matchingTriples) {

                for (final Long p2 : subPropertyOfMultiMap.get(p1)) {

                    final Triple result = new ImmutableTriple(triple.getSubject(), p2, triple.getObject());
                    outputTriples.add(result);
                }

            }
        }
    }

    return loops;

}

From source file:org.opendaylight.mdsal.dom.broker.DOMNotificationRouter.java

/**
 * Swaps registered listeners and triggers notification update
 *
 * @param newListeners/*  w  w  w  .  j av  a2 s . c om*/
 */
private void replaceListeners(
        final Multimap<SchemaPath, ListenerRegistration<? extends DOMNotificationListener>> newListeners) {
    listeners = newListeners;
    notifyListenerTypesChanged(newListeners.keySet());
}

From source file:org.opentestsystem.shared.security.service.RoleSpecificPermissionsService.java

@Override
protected Multimap<String, SbacRole> buildRolesFromParsedStrings(
        final Map<String, RoleToPermissionMapping> inRoleToPermissionMappings,
        final List<String[]> inRoleStrings) {
    Multimap<String, SbacRole> retRoles = ArrayListMultimap.create();
    Multimap<String, SbacPermission> roleNamesToLookFor = permissionResolver.getRoleBindings(componentName);
    if (inRoleStrings != null && roleNamesToLookFor != null) {
        for (String[] roleAttributes : inRoleStrings) {
            SbacRole role = extractRole(roleAttributes);
            if (roleNamesToLookFor.keySet().contains(role.getRoleName())) {
                role.setIsApplicableToTenant(true);
                role.setPermissions(roleNamesToLookFor.get(role.getRoleName()));
                retRoles.put(role.getRoleName(), role);
            }//w  w  w.  j ava  2  s  .  com
        }
    }
    return retRoles;
}

From source file:com.streamsets.pipeline.stage.destination.jdbc.JdbcTarget.java

@Override
@SuppressWarnings("unchecked")
public void write(Batch batch) throws StageException {
    Multimap<String, Record> partitions = ELUtils.partitionBatchByExpression(tableNameEval, tableNameVars,
            tableNameTemplate, batch);/*from   w  ww. ja v  a 2 s . c om*/
    Set<String> tableNames = partitions.keySet();
    for (String tableName : tableNames) {
        List<OnRecordErrorException> errors = recordWriters.getUnchecked(tableName)
                .writeBatch(partitions.get(tableName));
        for (OnRecordErrorException error : errors) {
            errorRecordHandler.onError(error);
        }
    }
}

From source file:com.dangdang.ddframe.rdb.sharding.merger.groupby.GroupByResultSet.java

private Collection<GroupByValue> reduce(final Multimap<GroupByKey, GroupByValue> mappedResult)
        throws SQLException {
    List<GroupByValue> result = new ArrayList<>(mappedResult.values().size() * columnLabels.size());
    for (GroupByKey key : mappedResult.keySet()) {
        Collection<GroupByValue> each = mappedResult.get(key);
        GroupByValue reduceResult = new GroupByValue();
        for (int i = 0; i < columnLabels.size(); i++) {
            int index = i + 1;
            Optional<AggregationColumn> aggregationColumn = findAggregationColumn(index);
            Comparable<?> value = null;
            if (aggregationColumn.isPresent()) {
                value = aggregate(aggregationColumn.get(), index, each);
            }/*from   w  ww  .j ava  2  s. c  o m*/
            value = null == value ? each.iterator().next().getValue(new ResultSetQueryIndex(index)) : value;
            reduceResult.put(index, columnLabels.get(i), value);
        }
        if (orderByColumns.isEmpty()) {
            reduceResult.addGroupByColumns(groupByColumns);
        } else {
            reduceResult.addOrderColumns(orderByColumns);
        }
        result.add(reduceResult);
    }
    Collections.sort(result);
    log.trace("Reduced result: {}", result);
    return result;
}

From source file:org.eclipse.xtext.linking.lazy.LazyLinker.java

@SuppressWarnings("unchecked")
protected void installQueuedLinks(Multimap<EStructuralFeature.Setting, INode> settingsToLink) {
    for (EStructuralFeature.Setting setting : settingsToLink.keySet()) {
        final EObject eObject = setting.getEObject();
        final EReference eRef = (EReference) setting.getEStructuralFeature();
        final Collection<INode> nodes = settingsToLink.get(setting);
        if (setting.getEStructuralFeature().isMany()) {
            EList<EObject> list = (EList<EObject>) setting.get(false);
            for (INode node : nodes) {
                final EObject proxy = createProxy(eObject, node, eRef);
                list.add(EcoreUtil.resolve(proxy, eObject));
            }/*from www.  j a va 2 s .c  o  m*/
        } else {
            final INode node = nodes.iterator().next();
            final EObject proxy = createProxy(eObject, node, eRef);
            setting.set(EcoreUtil.resolve(proxy, eObject));
        }
    }
}

From source file:org.napile.compiler.lang.resolve.processors.DeclarationResolver.java

private void checkRedeclarationsInNamespaces() {
    for (PackageDescriptor descriptor : context.getPackages().values()) {
        Multimap<Name, DeclarationDescriptor> simpleNameDescriptors = ((WritableScope) descriptor
                .getMemberScope()).getDeclaredDescriptorsAccessibleBySimpleName();
        for (Name name : simpleNameDescriptors.keySet()) {
            Collection<DeclarationDescriptor> descriptors = simpleNameDescriptors.get(name);

            if (descriptors.size() > 1) {
                for (DeclarationDescriptor declarationDescriptor : descriptors) {
                    for (PsiElement declaration : getDeclarationsByDescriptor(declarationDescriptor)) {
                        assert declaration != null;
                        trace.report(REDECLARATION.on(declaration, declarationDescriptor.getName().getName()));
                    }// w  w  w.j a v a 2s.  com
                }
            }
        }
    }
}

From source file:com.google.devtools.build.lib.query2.RdepsUnboundedVisitor.java

@Override
protected Visit getVisitResult(Iterable<DepAndRdep> depAndRdeps) throws InterruptedException {
    Collection<SkyKey> validRdeps = new ArrayList<>();

    // Multimap of dep to all the reverse deps in this visitation. Used to filter out the
    // disallowed deps.
    Multimap<SkyKey, SkyKey> reverseDepMultimap = ArrayListMultimap.create();
    for (DepAndRdep depAndRdep : depAndRdeps) {
        // The "roots" of our visitation (see #preprocessInitialVisit) have a null 'dep' field.
        if (depAndRdep.dep == null) {
            validRdeps.add(depAndRdep.rdep);
        } else {/* w w  w  .  j av  a 2 s .c  o  m*/
            reverseDepMultimap.put(depAndRdep.dep, depAndRdep.rdep);
        }
    }

    Multimap<SkyKey, SkyKey> packageKeyToTargetKeyMap = env
            .makePackageKeyToTargetKeyMap(Iterables.concat(reverseDepMultimap.values()));
    Set<PackageIdentifier> pkgIdsNeededForTargetification = packageKeyToTargetKeyMap.keySet().stream()
            .map(SkyQueryEnvironment.PACKAGE_SKYKEY_TO_PACKAGE_IDENTIFIER).collect(toImmutableSet());
    packageSemaphore.acquireAll(pkgIdsNeededForTargetification);

    try {
        // Filter out disallowed deps. We cannot defer the targetification any further as we do not
        // want to retrieve the rdeps of unwanted nodes (targets).
        if (!reverseDepMultimap.isEmpty()) {
            Collection<Target> filteredTargets = env.filterRawReverseDepsOfTransitiveTraversalKeys(
                    reverseDepMultimap.asMap(), packageKeyToTargetKeyMap);
            filteredTargets.stream().map(SkyQueryEnvironment.TARGET_TO_SKY_KEY).forEachOrdered(validRdeps::add);
        }
    } finally {
        packageSemaphore.releaseAll(pkgIdsNeededForTargetification);
    }

    ImmutableList<SkyKey> uniqueValidRdeps = validRdeps.stream().filter(validRdepUniquifier::unique)
            .collect(ImmutableList.toImmutableList());

    // Retrieve the reverse deps as SkyKeys and defer the targetification and filtering to next
    // recursive visitation.
    ImmutableList.Builder<DepAndRdep> depAndRdepsToVisitBuilder = ImmutableList.builder();
    env.graph
            .getReverseDeps(
                    uniqueValidRdeps)
            .entrySet()
            .forEach(reverseDepsEntry -> depAndRdepsToVisitBuilder.addAll(Iterables.transform(
                    Iterables.filter(reverseDepsEntry.getValue(),
                            Predicates.and(SkyQueryEnvironment.IS_TTV, universe)),
                    rdep -> new DepAndRdep(reverseDepsEntry.getKey(), rdep))));

    return new Visit(/*keysToUseForResult=*/ uniqueValidRdeps,
            /*keysToVisit=*/ depAndRdepsToVisitBuilder.build());
}

From source file:pt.ua.tm.trigner.documents.Documents.java

public void cleanFeatures(final String[] except) {
    List<String> exceptList = Arrays.asList(except);
    for (Corpus corpus : this) {
        for (Sentence sentence : corpus) {
            for (Token token : sentence) {
                Multimap<String, String> current = token.getFeaturesMap();
                //                    Multimap<String, String> next = HashMultimap.create();

                List<String> toRemove = new ArrayList<>();
                for (String key : current.keySet()) {
                    if (!exceptList.contains(key)) {
                        toRemove.add(key);
                    }/* w w  w. j a v  a2s.com*/
                }

                for (String keyToRemove : toRemove) {
                    current.removeAll(keyToRemove);
                }

                // Set new map
                //                    current = null;
                //                    token.setFeaturesMap(next);
            }
        }
    }
}

From source file:com.b2international.snowowl.datastore.server.importer.AbstractTerminologyImportValidator.java

private void checkDuplication() {

    for (final String attributeName : uniqueAttributes.keySet()) {
        final Multimap<String, String> attributeValueSheetNamesMap = uniqueAttributes.get(attributeName);
        for (final String attributeValue : attributeValueSheetNamesMap.keySet()) {
            final Collection<String> sheetNames = attributeValueSheetNamesMap.get(attributeValue);

            if (sheetNames.size() > 1) {
                for (final String sheetName : sheetNames) {
                    addDefect(sheetName, DefectType.DIFFERENCES,
                            "'" + attributeName + "' attribute must be unique.");
                }//  ww  w .  j  a  va  2  s .c  om
            }

        }
    }

}