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:org.nuxeo.ecm.platform.groups.audit.service.acl.AclExcelLayoutBuilderMultiColumn.java

@Override
protected void renderAcl(Multimap<String, Pair<String, Boolean>> userAcls) throws ClientException {
    for (String user : userAcls.keySet()) {
        List<Pair<String, Boolean>> acls = new ArrayList<Pair<String, Boolean>>(userAcls.get(user));
        int last = acls.size() - 1;

        // TODO: IF ACLS not contain an ACL that should be first or last,
        // thus showing border, post draw white cells

        for (int i = 0; i < acls.size(); i++) {
            boolean isFirst = false;// (i == 0);
            boolean isLast = false;// (i == last);

            Pair<String, Boolean> ace = acls.get(i);
            String permission = ace.a;
            boolean accept = ace.b;
            int aclColumn = layout.getUserAclColumn(Pair.of(user, permission));
            String aceText = "";// formatAce(ace)

            if (accept) {
                // draws an accept cell
                renderAcceptCell(isFirst, isLast, aclColumn, aceText);
            } else {
                // draws a deny cell
                renderDenyCell(isFirst, isLast, aclColumn, aceText);
            }/*from   ww  w.j  a  v  a  2s . co  m*/
        }
        // String info = formatAcl(userAcls.get(user));
    }
}

From source file:com.github.jcustenborder.kafka.connect.utils.templates.model.Configuration.java

private Configuration(Collection<Item> configs) {
    this.requiredConfigs = configs.stream().filter(Item::isRequired).collect(Collectors.toList());

    Multimap<String, Item> groupToItem = LinkedListMultimap.create();
    for (Item item : configs) {
        groupToItem.put(item.group, item);
    }/* ww  w. j  ava2  s. c o m*/
    List<Group> groups = new ArrayList<>();
    for (String group : groupToItem.keySet()) {
        Collection<Item> items = groupToItem.get(group);
        groups.add(new Group(group, new ArrayList<>(items)));
    }
    Collections.sort(groups);

    this.groups = ImmutableList.copyOf(groups);
}

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

public void putAll(Namespace namespace, Multimap<String, Object> valuesMap) {
    Session session = null;/* w  w  w  . ja v  a  2 s .co m*/
    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:org.dcache.nfs.v3.MountServer.java

@Override
public exports MOUNTPROC3_EXPORT_3(RpcCall call$) {

    exports eFullList = new exports();
    exports eList = eFullList;// ww w  .  ja  v  a2 s  . c o  m

    eList.value = null;

    Multimap<String, String> exports = groupBy(_exportFile.getExports());
    for (String path : exports.keySet()) {

        eList.value = new exportnode();
        eList.value.ex_dir = new dirpath(path);
        eList.value.ex_groups = new groups();
        eList.value.ex_groups.value = null;
        groups g = eList.value.ex_groups;

        for (String client : exports.get(path)) {

            g.value = new groupnode();
            g.value.gr_name = new name(client);
            g.value.gr_next = new groups();
            g.value.gr_next.value = null;

            g = g.value.gr_next;
        }

        eList.value.ex_next = new exports();
        eList.value.ex_next.value = null;
        eList = eList.value.ex_next;

    }
    return eFullList;
}

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

public void createReferenceUpdates(ElementRenameArguments elementRenameArguments, ResourceSet resourceSet,
        IRefactoringUpdateAcceptor updateAcceptor, IProgressMonitor monitor) {
    SubMonitor progress = SubMonitor.convert(monitor, "Updating references", 100);
    ResourceAccess resourceAccess = resourceAccessProvider.get();
    resourceAccess.registerResourceSet(resourceSet);

    ReferenceDescriptionAcceptor referenceDescriptionAcceptor = createFindReferenceAcceptor(updateAcceptor);
    referenceFinder.findAllReferences(/*from   w ww. j a v a 2 s.co m*/
            targetURIConverter.fromIterable(elementRenameArguments.getRenamedElementURIs()), resourceAccess,
            indexData, referenceDescriptionAcceptor, progress.newChild(2));
    Multimap<IReferenceUpdater, IReferenceDescription> updater2descriptions = referenceDescriptionAcceptor
            .getReferenceUpdater2ReferenceDescriptions();
    SubMonitor updaterProgress = progress.newChild(98).setWorkRemaining(updater2descriptions.keySet().size());
    for (IReferenceUpdater referenceUpdater : updater2descriptions.keySet()) {
        if (updaterProgress.isCanceled())
            return;
        referenceUpdater.createReferenceUpdates(elementRenameArguments,
                updater2descriptions.get(referenceUpdater), updateAcceptor, updaterProgress.newChild(1));
    }
}

From source file:org.apache.rya.mongodb.iter.RyaStatementBindingSetCursorIterator.java

public RyaStatementBindingSetCursorIterator(final MongoCollection<Document> coll,
        final Multimap<RyaStatement, BindingSet> rangeMap, final MongoDBStorageStrategy<RyaStatement> strategy,
        final Authorizations auths) {
    this.coll = coll;
    this.rangeMap = rangeMap;
    queryIterator = rangeMap.keySet().iterator();
    this.strategy = strategy;
    this.auths = auths;
}

From source file:net.shibboleth.idp.saml.saml2.profile.impl.FilterByQueriedAttributes.java

/** {@inheritDoc} */
@Override//from w  w w .ja  v  a 2  s  .  c  o m
protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {

    final Collection<IdPAttribute> keepers = new ArrayList<>(query.getAttributes().size());

    final Multimap<String, IdPAttribute> mapped = mapperService.mapAttributes(query.getAttributes());
    log.debug("{} Query content mapped to attribute IDs: {}", getLogPrefix(), mapped.keySet());

    for (final IdPAttribute attribute : attributeContext.getIdPAttributes().values()) {

        final Collection<IdPAttribute> requested = mapped.get(attribute.getId());

        if (!requested.isEmpty()) {
            log.debug("{} Attribute '{}' requested by query, checking for requested values", getLogPrefix(),
                    attribute.getId());

            final int count = filterRequestedValues(attribute, requested);
            if (count > 0) {
                log.debug("{} Retaining requested attribute '{}' with {} value(s)", getLogPrefix(),
                        attribute.getId(), count);
                keepers.add(attribute);
            } else {
                log.debug("{} Removing requested attribute '{}', no values left after filtering",
                        getLogPrefix(), attribute.getId());
            }
        } else {
            log.debug("{} Removing attribute '{}' not requested by query", getLogPrefix(), attribute.getId());
        }
    }

    attributeContext.setIdPAttributes(keepers);
}

From source file:rubedo.util.RemapHelper.java

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void _(WorldEvent.Load event) {

    if (Repl.replacements.size() < 1) {
        return;/*  w  w  w.jav  a 2 s .co m*/
    }
    for (Map.Entry<RegistryNamespaced, Multimap<String, Object>> entry : Repl.replacements.entrySet()) {
        RegistryNamespaced reg = entry.getKey();
        Multimap<String, Object> map = entry.getValue();
        Iterator<String> v = map.keySet().iterator();
        while (v.hasNext()) {
            String id = v.next();
            List<Object> c = (List<Object>) map.get(id);
            int i = 0, e = c.size() - 1;
            Object end = c.get(e);
            if (reg.getIDForObject(c.get(0)) != reg.getIDForObject(end)) {
                for (; i <= e; ++i) {
                    Object t = c.get(i);
                    Object oldThing = reg.getObject(id);
                    Repl.overwrite_do(reg, id, t, oldThing);
                    Repl.alterDelegate(oldThing, end);
                }
            }
        }
    }
}

From source file:com.streamsets.pipeline.stage.destination.s3.AmazonS3Target.java

@Override
public void write(Batch batch) throws StageException {
    Multimap<String, Record> partitions = ELUtils.partitionBatchByExpression(partitionEval, partitionVars,
            partitionTemplate, batch);/*ww  w.  j a  va 2  s .c om*/

    for (String partition : partitions.keySet()) {
        // commonPrefix always ends with a delimiter, so no need to append one to the end
        String keyPrefix = s3TargetConfigBean.s3Config.commonPrefix;
        // partition is optional
        if (!partition.isEmpty()) {
            keyPrefix += partition;
            if (!partition.endsWith(s3TargetConfigBean.s3Config.delimiter)) {
                keyPrefix += s3TargetConfigBean.s3Config.delimiter;
            }
        }
        keyPrefix += s3TargetConfigBean.fileNamePrefix + "-" + System.currentTimeMillis() + "-";

        Iterator<Record> records = partitions.get(partition).iterator();
        int writtenRecordCount = 0;
        DataGenerator generator;
        Record currentRecord;

        try {
            ByRefByteArrayOutputStream bOut = new ByRefByteArrayOutputStream();
            OutputStream out = bOut;

            // wrap with gzip compression output stream if required
            if (s3TargetConfigBean.compress) {
                out = new GZIPOutputStream(bOut);
            }

            generator = s3TargetConfigBean.getGeneratorFactory().getGenerator(out);
            while (records.hasNext()) {
                currentRecord = records.next();
                try {
                    generator.write(currentRecord);
                    writtenRecordCount++;
                } catch (StageException e) {
                    errorRecordHandler.onError(
                            new OnRecordErrorException(currentRecord, e.getErrorCode(), e.getParams()));
                } catch (IOException e) {
                    errorRecordHandler.onError(new OnRecordErrorException(currentRecord, Errors.S3_32,
                            currentRecord.getHeader().getSourceId(), e.toString(), e));
                }
            }
            generator.close();

            // upload file on Amazon S3 only if at least one record was successfully written to the stream
            if (writtenRecordCount > 0) {
                fileCount++;
                StringBuilder fileName = new StringBuilder();
                fileName = fileName.append(keyPrefix).append(fileCount);
                if (s3TargetConfigBean.compress) {
                    fileName = fileName.append(GZIP_EXTENSION);
                }

                // Avoid making a copy of the internal buffer maintained by the ByteArrayOutputStream by using
                // ByRefByteArrayOutputStream
                ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bOut.getInternalBuffer(),
                        0, bOut.size());

                PutObjectRequest putObjectRequest = new PutObjectRequest(s3TargetConfigBean.s3Config.bucket,
                        fileName.toString(), byteArrayInputStream, null);

                LOG.debug("Uploading object {} into Amazon S3",
                        s3TargetConfigBean.s3Config.bucket + s3TargetConfigBean.s3Config.delimiter + fileName);
                s3TargetConfigBean.s3Config.getS3Client().putObject(putObjectRequest);
                LOG.debug("Successfully uploaded object {} into Amazon S3",
                        s3TargetConfigBean.s3Config.bucket + s3TargetConfigBean.s3Config.delimiter + fileName);
            }
        } catch (AmazonClientException | IOException e) {
            LOG.error(Errors.S3_21.getMessage(), e.toString(), e);
            throw new StageException(Errors.S3_21, e.toString(), e);
        }
    }
}

From source file:com.github.rinde.rinsim.core.model.DependencyResolver.java

ImmutableSet<Model<?>> resolve() {
    addDefaultModels();/*from  w  w  w.  j  a va  2  s .c  o m*/
    final Multimap<Dependency, Dependency> dependencyGraph = constructDependencyGraph();

    if (LOGGER.isTraceEnabled()) {
        for (final Dependency dep : dependencyGraph.keySet()) {
            final StringBuilder sb = new StringBuilder();
            for (final Dependency d : dependencyGraph.get(dep)) {
                sb.append(d.modelBuilder).append(" ");
            }
            LOGGER.trace("{} requires: {}.", dep.modelBuilder.toString(), sb);
        }
    }

    while (!dependencyGraph.isEmpty()) {
        final List<Dependency> toRemove = new ArrayList<>();
        for (final Dependency dep : dependencyGraph.keys()) {
            final Collection<Dependency> dependencies = dependencyGraph.get(dep);
            boolean allResolved = true;
            for (final Dependency dependency : dependencies) {
                allResolved &= dependency.isResolved();
            }
            if (allResolved) {
                dep.build();
                toRemove.add(dep);
            }
        }

        for (final Dependency mb : toRemove) {
            dependencyGraph.removeAll(mb);
        }
        if (toRemove.isEmpty()) {
            throw new IllegalArgumentException("Could not resolve dependencies for " + dependencyGraph.keySet()
                    + ", most likely a circular dependency was declared.");
        }
    }

    final ImmutableSet.Builder<Model<?>> builder = ImmutableSet.builder();
    for (final Dependency cmb : builders) {
        builder.add(cmb.build());
    }
    return builder.build();
}