List of usage examples for com.google.common.collect Multimap keySet
Set<K> keySet();
From source file:org.gradle.model.internal.manage.schema.extract.ImplTypeSchemaExtractionStrategySupport.java
private <R> List<ModelProperty<?>> extractPropertySchemas(ModelSchemaExtractionContext<R> extractionContext, Multimap<String, Method> methodsByName) { List<ModelProperty<?>> properties = Lists.newArrayList(); Set<Method> handledMethods = Sets.newHashSet(); for (String methodName : methodsByName.keySet()) { Collection<Method> methods = methodsByName.get(methodName); List<Method> overloadedMethods = getOverloadedMethods(methods); if (overloadedMethods != null) { handleOverloadedMethods(extractionContext, overloadedMethods); continue; }//from w w w. j a va 2 s. c o m if (methodName.startsWith("get") && !methodName.equals("get")) { PropertyAccessorExtractionContext getterContext = new PropertyAccessorExtractionContext(methods, isGetterDefinedInManagedType(extractionContext, methodName, methods)); Character getterPropertyNameFirstChar = methodName.charAt(3); if (!Character.isUpperCase(getterPropertyNameFirstChar)) { handleInvalidGetter(extractionContext, getterContext, "the 4th character of the getter method name must be an uppercase character"); continue; } String propertyNameCapitalized = methodName.substring(3); String propertyName = StringUtils.uncapitalize(propertyNameCapitalized); String setterName = "set" + propertyNameCapitalized; Collection<Method> setterMethods = methodsByName.get(setterName); PropertyAccessorExtractionContext setterContext = !setterMethods.isEmpty() ? new PropertyAccessorExtractionContext(setterMethods) : null; ModelProperty<?> property = extractPropertySchema(extractionContext, propertyName, getterContext, setterContext, handledMethods); if (property != null) { properties.add(property); handledMethods.addAll(getterContext.getDeclaringMethods()); if (setterContext != null) { handledMethods.addAll(setterContext.getDeclaringMethods()); } } } } validateAllNecessaryMethodsHandled(extractionContext, methodsByName.values(), handledMethods); return properties; }
From source file:com.b2international.snowowl.datastore.index.ImmutableIndexCommitChangeSet.java
/** * Apply this {@link ImmutableIndexCommitChangeSet} on the given {@link RevisionWriter index transaction}. * //from w w w. j a v a2s . c om * @param index * @throws IOException */ @Override public void apply(RevisionWriter index) throws IOException { for (final Class<?> type : rawDeletions.keySet()) { final Map<Class<?>, Set<String>> map = Collections.<Class<?>, Set<String>>singletonMap(type, Sets.newHashSet(rawDeletions.get(type))); index.writer().removeAll(map); } for (Entry<String, Object> doc : rawMappings.entrySet()) { if (!rawDeletions.containsValue(doc.getKey())) { index.writer().put(doc.getKey(), doc.getValue()); } } final Multimap<Class<? extends Revision>, Long> copiedRevision = ImmutableMultimap .copyOf(revisionDeletions); for (Class<? extends Revision> type : copiedRevision.keySet()) { index.remove(type, copiedRevision.get(type)); } for (Entry<Long, Revision> doc : revisionMappings.entrySet()) { if (!revisionDeletions.containsValue(doc.getKey())) { index.put(doc.getKey(), doc.getValue()); } } }
From source file:com.google.devtools.build.lib.query2.RdepsBoundedVisitor.java
@Override protected Visit getVisitResult(Iterable<DepAndRdepAtDepth> depAndRdepAtDepths) throws InterruptedException { Map<SkyKey, Integer> shallowestRdepDepthMap = new HashMap<>(); depAndRdepAtDepths.forEach(depAndRdepAtDepth -> shallowestRdepDepthMap .merge(depAndRdepAtDepth.depAndRdep.rdep, depAndRdepAtDepth.rdepDepth, Integer::min)); 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 (DepAndRdepAtDepth depAndRdepAtDepth : depAndRdepAtDepths) { // The "roots" of our visitation (see #preprocessInitialVisit) have a null 'dep' field. if (depAndRdepAtDepth.depAndRdep.dep == null) { validRdeps.add(depAndRdepAtDepth.depAndRdep.rdep); } else {/*from w ww.j a v a 2 s . com*/ reverseDepMultimap.put(depAndRdepAtDepth.depAndRdep.dep, depAndRdepAtDepth.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(validRdep -> validRdepMinDepthUniquifier .uniqueAtDepthLessThanOrEqualTo(validRdep, shallowestRdepDepthMap.get(validRdep))) .collect(ImmutableList.toImmutableList()); // Don't bother getting the rdeps of the rdeps that are already at the depth bound. Iterable<SkyKey> uniqueValidRdepsBelowDepthBound = Iterables.filter(uniqueValidRdeps, uniqueValidRdep -> shallowestRdepDepthMap.get(uniqueValidRdep) < depth); // Retrieve the reverse deps as SkyKeys and defer the targetification and filtering to next // recursive visitation. Map<SkyKey, Iterable<SkyKey>> unfilteredRdepsOfRdeps = env.graph .getReverseDeps(uniqueValidRdepsBelowDepthBound); ImmutableList.Builder<DepAndRdepAtDepth> depAndRdepAtDepthsToVisitBuilder = ImmutableList.builder(); unfilteredRdepsOfRdeps.entrySet().forEach(entry -> { SkyKey rdep = entry.getKey(); int depthOfRdepOfRdep = shallowestRdepDepthMap.get(rdep) + 1; Streams.stream(entry.getValue()).filter(Predicates.and(SkyQueryEnvironment.IS_TTV, universe)) .forEachOrdered(rdepOfRdep -> { depAndRdepAtDepthsToVisitBuilder .add(new DepAndRdepAtDepth(new DepAndRdep(rdep, rdepOfRdep), depthOfRdepOfRdep)); }); }); return new Visit(/*keysToUseForResult=*/ uniqueValidRdeps, /*keysToVisit=*/ depAndRdepAtDepthsToVisitBuilder.build()); }
From source file:org.nnsoft.guice.junice.GuiceMockModule.java
@SuppressWarnings("unchecked") @Override/*from w ww . j ava 2 s . c o m*/ protected void configure() { final Multimap<Type, Field> fieldsByType = HashMultimap.create(); for (final Entry<Field, Object> entry : this.mockedFields.entrySet()) { fieldsByType.put(entry.getKey().getGenericType(), entry.getKey()); } for (final Type type : fieldsByType.keySet()) { final Collection<Field> fields = fieldsByType.get(type); boolean isTypeConflicts = false; if (fields.size() != 1) { isTypeConflicts = checkTypeConflict(fields); } checkState(!isTypeConflicts, " Found multiple annotation @%s for type: %s; binding skipped!.", Mock.class.getSimpleName(), type); for (final Field field : fields) { final TypeLiteral literal = TypeLiteral.get(type); final Mock annoBy = field.getAnnotation(Mock.class); final Object mock = this.mockedFields.get(field); if (annoBy.annotatedWith() != Mock.NoAnnotation.class) { bind(literal).annotatedWith(annoBy.annotatedWith()).toInstance(mock); } else if (!"".equals(annoBy.namedWith())) { bind(literal).annotatedWith(Names.named(annoBy.namedWith())).toInstance(mock); } else { bind(literal).toInstance(mock); } if (logger.isLoggable(Level.FINER)) { logger.finer(" Created binding for: " + type + " " + annoBy); } } } }
From source file:com.synflow.core.transformations.impl.StoreOnceTransformation.java
private Map<Var, Var> removeDuplicates(Multimap<Var, Var> multiMap) { Map<Var, Var> localMap = new LinkedHashMap<Var, Var>(); for (Var global : multiMap.keySet()) { Iterator<Var> it = multiMap.get(global).iterator(); if (!it.hasNext()) { continue; }//from w ww .j a v a 2 s. c o m Var local = it.next(); while (it.hasNext()) { Var duplicate = it.next(); for (Def def : new ArrayList<>(duplicate.getDefs())) { def.setVariable(local); } for (Use use : new ArrayList<>(duplicate.getUses())) { use.setVariable(local); } // just remove from container EcoreUtil.remove(duplicate); } localMap.put(global, local); } return localMap; }
From source file:org.eclipse.xtext.ui.refactoring.impl.AbstractReferenceUpdater.java
protected void createReferenceUpdates(ElementRenameArguments elementRenameArguments, Iterable<IReferenceDescription> referenceDescriptions, IRefactoringUpdateAcceptor updateAcceptor, RefactoringResourceSetProvider resourceSetProvider, IProgressMonitor monitor) { SubMonitor progress = SubMonitor.convert(monitor, 100); progress.beginTask("Sort references by project", 1); Multimap<IProject, IReferenceDescription> project2references = sorter.sortByProject(referenceDescriptions); SubMonitor allProjectsProgress = progress.newChild(98).setWorkRemaining(project2references.keySet().size()); for (IProject project : project2references.keySet()) { if (allProjectsProgress.isCanceled()) { throw new OperationCanceledException(); }//from w w w . ja va 2 s. co m Multimap<URI, IReferenceDescription> resource2references = sorter .sortByResource(project2references.get(project)); ResourceSet resourceSet = resourceSetProvider.get(project); StatusWrapper status = updateAcceptor.getRefactoringStatus(); createClusteredReferenceUpdates(elementRenameArguments, resource2references, resourceSet, updateAcceptor, status, allProjectsProgress.newChild(1)); } }
From source file:de.iteratec.iteraplan.businesslogic.exchange.timeseriesExcel.importer.TimeseriesExcelImporter.java
private void importTimeseriesEntries(Multimap<BuildingBlock, TimeseriesEntry> entriesMap, AttributeType at) { for (BuildingBlock bb : entriesMap.keySet()) { Timeseries timeseries = timeseriesService.loadTimeseriesByBuildingBlockAndAttributeType(bb, at); if (timeseries == null) { timeseries = new Timeseries(); timeseries.setBuildingBlock(bb); timeseries.setAttribute(at); }// w ww .j av a2 s . c o m for (TimeseriesEntry entry : entriesMap.get(bb)) { timeseries.addEntry(entry); } timeseriesService.saveOrUpdateWithBbUpdate(timeseries); } }
From source file:org.obiba.opal.web.gwt.app.client.report.list.ReportsView.java
@Override public void setReportTemplates(JsArray<ReportTemplateDto> templates) { reportList.clear();//from ww w .j a v a2s .c om // group templates by project Multimap<String, ReportTemplateDto> templateMap = ArrayListMultimap.create(); for (ReportTemplateDto template : JsArrays.toIterable(JsArrays.toSafeArray(templates))) { templateMap.get(template.getProject()).add(template); } for (String project : templateMap.keySet()) { reportList.add(new NavHeader( TranslationsUtils.replaceArguments(translations.reportTemplatesHeader(), project))); addReportTemplateLinks(templateMap.get(project)); } }
From source file:org.apache.james.mpt.onami.test.GuiceMockModule.java
@SuppressWarnings("unchecked") @Override/*from w ww .j a v a 2s . co m*/ protected void configure() { final Multimap<Type, Field> fieldsByType = HashMultimap.create(); for (final Entry<Field, Object> entry : this.mockedFields.entrySet()) { fieldsByType.put(entry.getKey().getGenericType(), entry.getKey()); } for (final Type type : fieldsByType.keySet()) { final Collection<Field> fields = fieldsByType.get(type); boolean isTypeConflicts = false; if (fields.size() != 1) { isTypeConflicts = checkTypeConflict(fields); } checkState(!isTypeConflicts, " Found multiple annotation @%s for type: %s; binding skipped!.", Mock.class.getSimpleName(), type); for (final Field field : fields) { @SuppressWarnings("rawtypes") final TypeLiteral literal = TypeLiteral.get(type); final Mock annoBy = field.getAnnotation(Mock.class); final Object mock = this.mockedFields.get(field); if (annoBy.annotatedWith() != Mock.NoAnnotation.class) { bind(literal).annotatedWith(annoBy.annotatedWith()).toInstance(mock); } else if (!"".equals(annoBy.namedWith())) { bind(literal).annotatedWith(Names.named(annoBy.namedWith())).toInstance(mock); } else { bind(literal).toInstance(mock); } if (LOGGER.isLoggable(Level.FINER)) { LOGGER.finer(" Created binding for: " + type + " " + annoBy); } } } }
From source file:uk.ac.ebi.metingear.tools.link.MergeTool.java
@Override public void process() { Reconstruction reconstruction = DefaultReconstructionManager.getInstance().active(); Key key = (Key) mergeKey.getSelectedItem(); Multimap<String, Metabolite> metabolites = HashMultimap.create(reconstruction.metabolome().size(), 2); for (Metabolite m : reconstruction.metabolome()) { metabolites.put(key.key(m), m);/* www . ja va 2 s .co m*/ } CompoundEdit edit = new CompoundEdit(); Set<String> keys = metabolites.keySet(); for (String k : keys) { List<Metabolite> ms = new ArrayList<Metabolite>(metabolites.get(k)); if (ms.size() > 1) { AppliableEdit subedit = new MergeMetaboliteEdit(ms, union(ms.get(0)), reconstruction); subedit.apply(); edit.addEdit(subedit); } } edit.end(); addEdit(edit); }