List of usage examples for com.google.common.collect SetMultimap entries
@Override Set<Map.Entry<K, V>> entries();
Because a SetMultimap has unique values for a given key, this method returns a Set , instead of the java.util.Collection specified in the Multimap interface.
From source file:org.eclipse.gef4.mvc.policies.CreationPolicy.java
/** * Creates an {@link IContentPart} for the given content {@link Object} and * establishes parent and anchored relationships for the newly created part. * Besides, operations are created for the establishment of the parent and * anchored relationships within the content model. These operations are * part of the operation returned by {@link #commit()}. * * @param content/*from w ww. j a va 2 s. c o m*/ * The content {@link Object} to be created. * @param parent * The {@link IContentPart} where the <i>content</i> is added as * a child. * @param index * The index for the new element. * @param anchoreds * The {@link IContentPart} whose content should be attached to * the new content under the given roles. * @return The {@link IContentPart} controlling the newly created content. */ @SuppressWarnings("serial") public IContentPart<VR, ? extends VR> create(Object content, IContentPart<VR, ? extends VR> parent, int index, SetMultimap<IContentPart<VR, ? extends VR>, String> anchoreds) { checkInitialized(); if (content == null) { throw new IllegalArgumentException("The given content may not be null."); } if (parent == null) { throw new IllegalArgumentException("The given parent may not be null."); } if (anchoreds == null) { throw new IllegalArgumentException("The given anchored parts may not be null"); } // create content part beforehand IContentPart<VR, ? extends VR> contentPart = contentPartFactory.createContentPart(content, null, null); // establish relationships to parent and anchored parts contentPart.setContent(content); parent.addChild(contentPart, index); for (Entry<IContentPart<VR, ? extends VR>, String> anchored : anchoreds.entries()) { anchored.getKey().attachToAnchorage(contentPart, anchored.getValue()); } // register the content part, so that the ContentBehavior // synchronization reuses it (when committing the create operation) contentPartPool.add(contentPart); // add to parent via content policy ContentPolicy<VR> parentContentPolicy = parent.getAdapter(new TypeToken<ContentPolicy<VR>>() { }.where(new TypeParameter<VR>() { }, Types.<VR>argumentOf(getHost().getRoot().getViewer().getClass()))); if (parentContentPolicy == null) { throw new IllegalStateException("No ContentPolicy registered for <" + parent + ">."); } parentContentPolicy.init(); parentContentPolicy.addContentChild(content, index); ITransactionalOperation addToParentOperation = parentContentPolicy.commit(); if (addToParentOperation != null) { getCompositeOperation().add(addToParentOperation); } // add anchoreds via content policy for (IContentPart<VR, ? extends VR> anchored : anchoreds.keys()) { ContentPolicy<VR> anchoredPolicy = anchored.getAdapter(new TypeToken<ContentPolicy<VR>>() { }.where(new TypeParameter<VR>() { }, Types.<VR>argumentOf(getHost().getRoot().getViewer().getClass()))); if (anchoredPolicy == null) { throw new IllegalStateException("No ContentPolicy registered for <" + anchored + ">."); } anchoredPolicy.init(); for (String role : anchoreds.get(anchored)) { anchoredPolicy.attachToContentAnchorage(content, role); } ITransactionalOperation attachToAnchorageOperation = anchoredPolicy.commit(); if (attachToAnchorageOperation != null) { getCompositeOperation().add(attachToAnchorageOperation); } } // set as focus part ITransactionalOperation focusOperation = createFocusOperation(contentPart); if (focusOperation != null) { getCompositeOperation().add(focusOperation); } // select the newly created part ITransactionalOperation selectOperation = createSelectOperation(contentPart); if (selectOperation != null) { getCompositeOperation().add(selectOperation); } locallyExecuteOperation(); return contentPart; }
From source file:edu.cmu.lti.oaqa.baseqa.evidence.concept.ConceptMerger.java
@SuppressWarnings("unchecked") @Override//from w w w . j a v a 2 s . com public void process(JCas jcas) throws AnalysisEngineProcessException { // create views and get all concepts in the views List<JCas> views = new ArrayList<>(); if (includeDefaultView) { views.add(jcas); } views.addAll(ViewType.listViews(jcas, viewNamePrefix)); List<Concept> concepts = views.stream().map(TypeUtil::getConcepts).flatMap(Collection::stream) .collect(toList()); // preserve concept fields Set<String> uuids = new HashSet<>(); SetMultimap<String, String> uuid2ids = HashMultimap.create(); SetMultimap<String, String> uuid2names = HashMultimap.create(); SetMultimap<String, String> uuid2uris = HashMultimap.create(); SetMultimap<String, ConceptMention> uuid2mentions = HashMultimap.create(); SetMultimap<String, List<String>> uuid2types = HashMultimap.create(); for (Concept concept : concepts) { String uuid = UUID_PREFIX + UUID.randomUUID().toString(); uuids.add(uuid); uuid2ids.putAll(uuid, TypeUtil.getConceptIds(concept)); uuid2names.putAll(uuid, TypeUtil.getConceptNames(concept)); uuid2uris.putAll(uuid, TypeUtil.getConceptUris(concept)); uuid2mentions.putAll(uuid, TypeUtil.getConceptMentions(concept)); // also remove duplicated concept type entries TypeUtil.getConceptTypes(concept).forEach(type -> uuid2types.put(uuid, toTypeList(type))); } // connectivity detection for merging UndirectedGraph<String, DefaultEdge> graph = new SimpleGraph<>(DefaultEdge.class); uuids.forEach(graph::addVertex); uuid2ids.values().forEach(graph::addVertex); uuid2ids.entries().forEach(entry -> graph.addEdge(entry.getKey(), entry.getValue())); if (useName) { uuid2names.values().stream().map(ConceptMerger::nameKey).forEach(graph::addVertex); uuid2names.entries().forEach(entry -> graph.addEdge(entry.getKey(), nameKey(entry.getValue()))); } views.forEach(view -> view.removeAllIncludingSubtypes(Concept.type)); ConnectivityInspector<String, DefaultEdge> ci = new ConnectivityInspector<>(graph); Multiset<Integer> mergedSizes = HashMultiset.create(); List<Concept> mergedConcepts = ci.connectedSets().stream().map(subgraph -> { Set<String> cuuids = subgraph.stream().filter(str -> str.startsWith(UUID_PREFIX)).collect(toSet()); List<String> ids = cuuids.stream().map(uuid2ids::get).flatMap(Set::stream).filter(Objects::nonNull) .distinct().collect(toList()); List<String> names = cuuids.stream().map(uuid2names::get).flatMap(Set::stream).filter(Objects::nonNull) .distinct().collect(toList()); List<String> uris = cuuids.stream().map(uuid2uris::get).flatMap(Set::stream).filter(Objects::nonNull) .distinct().collect(toList()); List<ConceptType> types = cuuids.stream().map(uuid2types::get).flatMap(Set::stream) .filter(Objects::nonNull).distinct().map(type -> parseTypeList(jcas, type)).collect(toList()); List<ConceptMention> mentions = cuuids.stream().map(uuid2mentions::get).flatMap(Set::stream) .filter(Objects::nonNull).collect(toList()); mergedSizes.add(cuuids.size()); return TypeFactory.createConcept(jcas, names, uris, ImmutableList.copyOf(ids), mentions, types); }).collect(toList()); mergedConcepts.forEach(Concept::addToIndexes); LOG.info("Merged concepts from {} concepts.", mergedSizes); if (LOG.isDebugEnabled()) { mergedConcepts.stream().map(TypeUtil::toString).forEachOrdered(c -> LOG.debug(" - {}", c)); } }
From source file:eu.esdihumboldt.hale.ui.style.TypeStyleHandler.java
/** * @see IHandler#execute(ExecutionEvent) *//*from w w w.j a va2 s . c om*/ @Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection selection = HandlerUtil.getCurrentSelection(event); // collect types and associated data sets SetMultimap<DataSet, TypeDefinition> types = HashMultimap.create(); if (selection instanceof IStructuredSelection && !selection.isEmpty()) { for (Object object : ((IStructuredSelection) selection).toArray()) { if (object instanceof TypeDefinition) { TypeDefinition type = (TypeDefinition) object; if (!types.containsValue(type)) { DataSet dataSet = findDataSet(type); types.put(dataSet, type); } } if (object instanceof EntityDefinition) { EntityDefinition entityDef = (EntityDefinition) object; if (entityDef.getPropertyPath().isEmpty()) { DataSet dataSet = (entityDef.getSchemaSpace() == SchemaSpaceID.SOURCE) ? (DataSet.SOURCE) : (DataSet.TRANSFORMED); types.put(dataSet, entityDef.getType()); } } if (object instanceof InstanceReference) { InstanceService is = (InstanceService) HandlerUtil.getActiveWorkbenchWindow(event) .getWorkbench().getService(InstanceService.class); object = is.getInstance((InstanceReference) object); } if (object instanceof Instance) { Instance instance = (Instance) object; types.put(instance.getDataSet(), instance.getDefinition()); } } } Pair<TypeDefinition, DataSet> typeInfo = null; // select a type if (types.size() == 1) { Entry<DataSet, TypeDefinition> entry = types.entries().iterator().next(); typeInfo = new Pair<TypeDefinition, DataSet>(entry.getValue(), entry.getKey()); } else if (!types.isEmpty()) { // choose through dialog DataSetTypeSelectionDialog dialog = new DataSetTypeSelectionDialog( Display.getCurrent().getActiveShell(), "Multiple types: select which to change the style for", null, types); if (dialog.open() == DataSetTypeSelectionDialog.OK) { typeInfo = dialog.getObject(); } } if (typeInfo != null) { try { FeatureStyleDialog dialog = new FeatureStyleDialog(typeInfo.getFirst(), typeInfo.getSecond()); dialog.setBlockOnOpen(false); dialog.open(); } catch (Exception e) { throw new ExecutionException("Could not open style dialog", e); } } return null; }
From source file:ome.services.graphs.GraphTraversal.java
/** * Load a specific link property's object relationships into the various cache fields of {@link Planning}. * @param linkProperty the link property being processed * @param query the HQL to query the property's object relationships * @param ids the IDs of the related objects * @return which linker objects are related to which linked objects by the given property * @throws GraphException if the objects could not be converted to unloaded instances */// w w w . j av a 2 s . c om private List<Entry<CI, CI>> getLinksToCache(CP linkProperty, String query, Collection<Long> ids) throws GraphException { final String linkedClassName = getLinkedClass(linkProperty); final boolean propertyIsAccessible = model.isPropertyAccessible(linkProperty.className, linkProperty.propertyName); final SetMultimap<Long, Long> linkerToLinked = HashMultimap.create(); for (final List<Long> idsBatch : Iterables.partition(ids, BATCH_SIZE)) { for (final Object[] result : (List<Object[]>) session.createQuery(query) .setParameterList("ids", idsBatch).list()) { linkerToLinked.put((Long) result[0], (Long) result[1]); } } final List<Entry<CI, CI>> linkerLinked = new ArrayList<Entry<CI, CI>>(); final Map<Long, CI> linkersById = findObjectDetails(linkProperty.className, linkerToLinked.keySet()); final Map<Long, CI> linkedsById = findObjectDetails(linkedClassName, new HashSet<Long>(linkerToLinked.values())); for (final Entry<Long, Long> linkerIdLinkedId : linkerToLinked.entries()) { final CI linker = linkersById.get(linkerIdLinkedId.getKey()); final CI linked = linkedsById.get(linkerIdLinkedId.getValue()); if (!planning.detailsNoted.containsKey(linker)) { log.warn("failed to query for " + linker); } else if (!planning.detailsNoted.containsKey(linked)) { log.warn("failed to query for " + linked); } else { linkerLinked.add(Maps.immutableEntry(linker, linked)); if (propertyIsAccessible) { planning.befores.put(linked, linker); planning.afters.put(linker, linked); } if (log.isDebugEnabled()) { log.debug(linkProperty.toCPI(linker.id) + " links to " + linked); } } } return linkerLinked; }
From source file:org.nuxeo.runtime.test.runner.RuntimeFeature.java
/** * Deploys bundles specified in the @Bundles annotation. *//*from w ww .ja v a2 s . co m*/ protected void deployTestClassBundles(FeaturesRunner runner) throws Exception { Set<String> bundles = new HashSet<String>(); Map<String, Collection<String>> mainDeployments = new HashMap<>(); SetMultimap<String, String> mainIndex = Multimaps.newSetMultimap(mainDeployments, new Supplier<Set<String>>() { @Override public Set<String> get() { return new HashSet<String>(); } }); Map<String, Collection<String>> localDeployments = new HashMap<>(); SetMultimap<String, String> localIndex = Multimaps.newSetMultimap(localDeployments, new Supplier<Set<String>>() { @Override public Set<String> get() { return new HashSet<String>(); } }); indexBundleResources(runner, bundles, mainIndex, getDeployments()); indexBundleResources(runner, bundles, localIndex, getLocalDeployments()); AssertionError errors = new AssertionError("cannot deploy components"); for (String name : bundles) { Bundle bundle = null; try { harness.deployBundle(name); bundle = harness.getOSGiAdapter().getBundle(name); } catch (Exception error) { errors.addSuppressed(error); continue; } try { // deploy bundle contribs for (String resource : mainIndex.removeAll(name)) { try { harness.deployContrib(name, resource); } catch (Exception error) { errors.addSuppressed(error); } } // deploy local contribs for (String resource : localIndex.removeAll(name)) { URL url = runner.getTargetTestResource(name); if (url == null) { url = bundle.getEntry(resource); } if (url == null) { url = runner.getTargetTestClass().getClassLoader().getResource(resource); } if (url == null) { throw new AssertionError("Cannot find " + resource + " in " + name); } harness.deployTestContrib(name, url); } } catch (Exception error) { errors.addSuppressed(error); } } for (Map.Entry<String, String> resource : mainIndex.entries()) { try { harness.deployContrib(resource.getKey(), resource.getValue()); } catch (Exception error) { errors.addSuppressed(error); } } for (Map.Entry<String, String> resource : localIndex.entries()) { try { harness.deployTestContrib(resource.getKey(), resource.getValue()); } catch (Exception error) { errors.addSuppressed(error); } } if (errors.getSuppressed().length > 0) { throw errors; } }