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

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

Introduction

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

Prototype

Multiset<K> keys();

Source Link

Document

Returns a view collection containing the key from each key-value pair in this multimap, without collapsing duplicates.

Usage

From source file:io.nuun.kernel.core.internal.scanner.disk.ClasspathScannerDisk.java

@Override
public void scanClasspathForMetaAnnotationRegex(final String metaAnnotationRegex, final Callback callback) {
    //        ConfigurationBuilder configurationBuilder = configurationBuilder();
    //        Set<URL> computeUrls = computeUrls();
    //        Reflections reflections = new Reflections(configurationBuilder.addUrls(computeUrls).setScanners(new TypesScanner()));

    queue(new ScannerCommand() {
        @Override//from   ww  w . j a  va2s  .  c o m
        public void execute(Reflections reflections) {
            Multimap<String, String> multimap = reflections.getStore().get(TypesScanner.class);

            Collection<Class<?>> typesAnnotatedWith = Sets.newHashSet();

            for (String className : multimap.keys()) {
                Class<?> klass = toClass(className);
                if (metaAnnotationRegex != null && klass != null
                        && AssertUtils.hasAnnotationDeepRegex(klass, metaAnnotationRegex)
                        && !klass.isAnnotation())
                //            if ( annotationType != null && klass != null &&  AssertUtils.hasAnnotationDeep(klass, annotationType) && ! klass.isAnnotation() )
                {
                    typesAnnotatedWith.add(klass);
                }
            }
            callback.callback(postTreatment(typesAnnotatedWith));
        }

        @Override
        public Scanner scanner() {
            return new TypesScanner();
        }
    });
}

From source file:org.nuunframework.kernel.internal.scanner.ClasspathScannerInternal.java

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override//from  w w  w . j a  va 2s .co  m
public void scanClasspathForMetaAnnotation(final Class<? extends Annotation> annotationType,
        final Callback callback) {
    //        ConfigurationBuilder configurationBuilder = configurationBuilder();
    //        Set<URL> computeUrls = computeUrls();
    //        Reflections reflections = new Reflections(configurationBuilder.addUrls(computeUrls).setScanners(new TypesScanner()));

    queue(new ScannerCommand() {
        @Override
        public void execute(Reflections reflections) {
            Multimap<String, String> multimap = reflections.getStore().get(TypesScanner.class);
            Collection<Class<?>> typesAnnotatedWith = Sets.newHashSet();
            for (String className : multimap.keys()) {
                Class<?> klass = toClass(className);
                if (annotationType != null && klass != null
                        && AssertUtils.hasAnnotationDeep(klass, annotationType) && !klass.isAnnotation()) {
                    typesAnnotatedWith.add(klass);
                }
            }
            callback.callback((Collection) postTreatment((Collection) typesAnnotatedWith));
        }

        @Override
        public Scanner scanner() {
            return new TypesScanner();
        }

    });

}

From source file:org.nuunframework.kernel.internal.scanner.ClasspathScannerInternal.java

@Override
public void scanClasspathForMetaAnnotationRegex(final String metaAnnotationRegex, final Callback callback) {
    //        ConfigurationBuilder configurationBuilder = configurationBuilder();
    //        Set<URL> computeUrls = computeUrls();
    //        Reflections reflections = new Reflections(configurationBuilder.addUrls(computeUrls).setScanners(new TypesScanner()));

    queue(new ScannerCommand() {
        @Override/* w  ww .  j a v  a 2 s  .  c o  m*/
        public void execute(Reflections reflections) {
            Multimap<String, String> multimap = reflections.getStore().get(TypesScanner.class);

            Collection<Class<?>> typesAnnotatedWith = Sets.newHashSet();

            for (String className : multimap.keys()) {
                Class<?> klass = toClass(className);
                if (metaAnnotationRegex != null && klass != null
                        && AssertUtils.hasAnnotationDeepRegex(klass, metaAnnotationRegex)
                        && !klass.isAnnotation())
                //            if ( annotationType != null && klass != null &&  AssertUtils.hasAnnotationDeep(klass, annotationType) && ! klass.isAnnotation() )
                {
                    typesAnnotatedWith.add(klass);
                }
            }
            callback.callback((Collection) postTreatment((Collection) typesAnnotatedWith));
        }

        @Override
        public Scanner scanner() {
            return new TypesScanner();
        }
    });
}

From source file:com.zimbra.cs.db.DbBlobConsistency.java

public static void delete(DbConnection conn, Mailbox mbox, Multimap<Integer, Integer> idRevs)
        throws ServiceException {
    Set<Integer> mail_itemIds = new HashSet<Integer>();
    Multimap<Integer, Integer> rev_itemIds = HashMultimap.create();
    for (Integer itemId : idRevs.keySet()) {
        Collection<Integer> revs = idRevs.get(itemId);
        for (int rev : revs) {
            if (rev == 0) {
                mail_itemIds.add(itemId);
            } else {
                rev_itemIds.put(itemId, rev);
            }/*from w  ww .j  a v a 2s  .c om*/
        }
    }

    if (mail_itemIds.size() > 0) {
        PreparedStatement miDumpstmt = null;
        try {
            StringBuffer sql = new StringBuffer();
            sql.append("DELETE FROM ").append(DbMailItem.getMailItemTableName(mbox, true)).append(" WHERE ")
                    .append(DbMailItem.IN_THIS_MAILBOX_AND).append(DbUtil.whereIn("id", mail_itemIds.size()));

            miDumpstmt = conn.prepareStatement(sql.toString());
            int pos = 1;
            pos = DbMailItem.setMailboxId(miDumpstmt, mbox, pos);
            for (int itemId : mail_itemIds) {
                miDumpstmt.setInt(pos++, itemId);
            }
            miDumpstmt.execute();
        } catch (SQLException e) {
            throw ServiceException.FAILURE(
                    "deleting " + idRevs.size() + " item(s): " + DbMailItem.getIdListForLogging(idRevs.keys())
                            + " from " + DbMailItem.TABLE_MAIL_ITEM_DUMPSTER + " table",
                    e);
        } finally {
            DbPool.quietCloseStatement(miDumpstmt);
        }
    }

    if (rev_itemIds.size() > 0) {
        PreparedStatement revDumpstmt = null;
        try {
            StringBuffer sql = new StringBuffer();
            sql.append("DELETE FROM ").append(DbMailItem.getRevisionTableName(mbox, true)).append(" WHERE ")
                    .append(DbMailItem.IN_THIS_MAILBOX_AND).append(DbUtil
                            .whereIn(Db.getInstance().concat("item_id", "'-'", "version"), rev_itemIds.size()));

            revDumpstmt = conn.prepareStatement(sql.toString());
            int pos = 1;
            pos = DbMailItem.setMailboxId(revDumpstmt, mbox, pos);
            for (Integer itemId : rev_itemIds.keySet()) {
                Collection<Integer> revs = rev_itemIds.get(itemId);
                for (int rev : revs) {
                    revDumpstmt.setString(pos++, itemId + "-" + rev);
                }
            }
            revDumpstmt.execute();
        } catch (SQLException e) {
            throw ServiceException.FAILURE(
                    "deleting " + idRevs.size() + " item(s): " + DbMailItem.getIdListForLogging(idRevs.keys())
                            + " from " + DbMailItem.TABLE_REVISION_DUMPSTER + " table",
                    e);
        } finally {
            DbPool.quietCloseStatement(revDumpstmt);
        }
    }
}

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

ImmutableSet<Model<?>> resolve() {
    addDefaultModels();//from  w  w w .j a v a 2s  . 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();
}

From source file:com.flexive.rest.ContentService.java

private void addGroup(Map<String, Object> result, FxGroupData group, Mode mode) {
    Multimap<String, FxData> multData = null; // properties and groups with max. mult > 1 (rendered as lists)

    for (FxData data : group.getChildren()) {
        final String key = data.getAlias();
        if (data.getAssignmentMultiplicity().getMax() > 1) {
            // gather all instances of this property or group and render them afterwards
            if (multData == null) {
                multData = ArrayListMultimap.create();
            }/*w  w w  .  j  a va2  s  .  c o  m*/
            multData.put(data.getAlias(), data);
        } else {
            result.put(key, encode(data, mode));
        }
    }

    if (multData != null) {
        // render elements with max. mult. > 1 as lists
        for (String alias : multData.keys()) {
            final Collection<FxData> values = multData.get(alias);
            final List<Object> elements = Lists.newArrayListWithCapacity(values.size());
            for (FxData data : values) {
                elements.add(encode(data, mode));
            }
            result.put(alias, elements);
        }
    }
}

From source file:com.github.autermann.wps.commons.WPS.java

public WPS addParser(Class<? extends IParser> clazz, Iterable<Format> formats,
        Multimap<String, String> properties) {
    lock.lock();/*w w w  .j  av a  2s  . c  o  m*/
    try {
        checkState(!isRunning());
        Parser parser = getConfig().getDatahandlers().getParserList().addNewParser();
        parser.setActive(true);
        parser.setClassName(clazz.getName());
        parser.setName("parser" + parserCount.getAndIncrement());
        if (formats != null) {
            for (Format f : formats) {
                f.encodeTo(parser.addNewFormat());
            }
        }
        if (properties != null) {
            for (String property : properties.keys()) {
                for (String value : properties.get(property)) {
                    Property p = parser.addNewProperty();
                    p.setActive(true);
                    p.setName(property);
                    p.setStringValue(value);
                }
            }
        }
        return this;
    } finally {
        lock.unlock();
    }
}

From source file:com.github.autermann.wps.commons.WPS.java

public WPS addGenerator(Class<? extends IGenerator> clazz, Iterable<Format> formats,
        Multimap<String, String> properties) {
    lock.lock();//from   w ww .jav a  2s.com
    try {
        checkState(!isRunning());
        Generator generator = getConfig().getDatahandlers().getGeneratorList().addNewGenerator();
        generator.setActive(true);
        generator.setClassName(clazz.getName());
        generator.setName("generator" + generatorCount.getAndIncrement());
        if (formats != null) {
            for (Format f : formats) {
                f.encodeTo(generator.addNewFormat());
            }
        }
        if (properties != null) {
            for (String property : properties.keys()) {
                for (String value : properties.get(property)) {
                    Property p = generator.addNewProperty();
                    p.setActive(true);
                    p.setName(property);
                    p.setStringValue(value);
                }
            }
        }
        return this;
    } finally {
        lock.unlock();
    }
}

From source file:io.redlink.sdk.impl.analysis.model.RDFStructureParser.java

private Collection<Enhancement> resolveRelations(Multimap<Enhancement, String> relations,
        RepositoryConnection conn) throws EnhancementParserException {

    Queue<String> toParse = new LinkedList<String>();
    toParse.addAll(Sets.newHashSet(relations.values()));
    Map<String, Enhancement> allRelations = new HashMap<String, Enhancement>();
    Collection<Enhancement> initialEnhancements = relations.keys();

    while (!toParse.isEmpty()) {
        String nextRelation = toParse.poll();
        Enhancement nextEnhancement = parseEnhancement(nextRelation, conn, toParse, relations);

        if (nextEnhancement != null)
            allRelations.put(nextRelation, nextEnhancement);
    }//from   ww w  .j  a  va2 s .c o m

    for (Enhancement e : relations.keys()) {
        Collection<String> relationsUris = relations.get(e);
        Collection<Enhancement> nextRelEnhancements = Sets.newHashSet();
        for (String uri : relationsUris)
            if (uri != null)
                nextRelEnhancements.add(allRelations.get(uri));
        e.setRelations(nextRelEnhancements);
    }

    return initialEnhancements;
}

From source file:tufts.vue.VueApplet.java

@SuppressWarnings("unchecked")
public static void addLinksToMap(final String content) {
    AccessController.doPrivileged(new PrivilegedAction() {

        public Object run() {
            //        Reader reader = openReader();
            javax.xml.parsers.DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setIgnoringElementContentWhitespace(true);
            factory.setIgnoringComments(true);
            //factory.setCoalescing(true);
            factory.setValidating(false);
            // We don't use is.setEncoding(), as openReader will already have handled that
            //      is.setCharacterStream(reader);
            InputStream is;/*from  w ww .j av a2  s .c o  m*/
            try {
                is = new java.io.ByteArrayInputStream(content.getBytes("UTF-8"));
                final org.w3c.dom.Document doc = factory.newDocumentBuilder().parse((InputStream) is);
                NodeList nodeLst = doc.getElementsByTagName("link");

                //build multimap of links
                Multimap<String, String> map = Multimaps.newArrayListMultimap();
                for (int s = 0; s < nodeLst.getLength(); s++) {

                    Node fstNode = nodeLst.item(s);

                    if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
                        NamedNodeMap atts = fstNode.getAttributes();

                        Node n = atts.item(0);
                        Node val = atts.item(1);

                        map.put(n.getNodeValue(), val.getNodeValue());
                    }

                }

                java.util.Collection<LWComponent> comps = VUE.getActiveMap().getAllDescendents();
                java.util.Iterator<LWComponent> iter = comps.iterator();
                //build map of data row nodes
                HashMap<String, LWNode> dataRowNodes = new HashMap<String, LWNode>();
                while (iter.hasNext()) {
                    LWComponent comp = iter.next();
                    if (comp.isDataRowNode()) {
                        String fromId = comp.getDataValue("id");
                        dataRowNodes.put(fromId, (LWNode) comp);
                    }
                }

                //draw links
                Multiset<String> keys = map.keys();
                java.util.Iterator<String> linkIterator = keys.iterator();

                while (linkIterator.hasNext()) {
                    String fromId = linkIterator.next();

                    Collection<String> toIds = map.get(fromId);
                    java.util.Iterator<String> toIdIterator = toIds.iterator();
                    while (toIdIterator.hasNext()) {
                        String tid = toIdIterator.next();
                        LWNode fromNode = dataRowNodes.get(fromId);
                        LWNode toNode = dataRowNodes.get(tid);

                        if (fromNode != null && toNode != null) {
                            LWLink link = new LWLink(fromNode, toNode);
                            VUE.getActiveMap().add(link);
                        }
                    }
                }

            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SAXException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ParserConfigurationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        };
    });

}