List of usage examples for com.google.common.collect Multimap isEmpty
boolean isEmpty();
From source file:uk.ac.ebi.metingear.tools.link.AssociateReactions.java
@Override public void process() { Reconstruction reconstruction = DefaultReconstructionManager.getInstance().active(); Key reactionKey = (Key) reactionKeyComboBox.getSelectedItem(); Key productKey = (Key) productKeyComboBox.getSelectedItem(); int n = reconstruction.getReactome().size(); Multimap<String, Reaction> reactionMap = HashMultimap.create(n, 1); for (Reaction reaction : reconstruction.getReactome()) { for (String key : reactionKey.keys(reaction)) { reactionMap.put(key, reaction); }//from www . ja v a 2s. c o m } if (reactionMap.isEmpty()) { addReport( new WarningMessage("no reactions were keyed using '" + reactionKey + "', check configuration")); return; } EditBuilder builder = new EditBuilder(reconstruction); for (GeneProduct gp : reconstruction.proteome()) { for (String key : productKey.keys(gp)) { for (Reaction reaction : reactionMap.get(key)) { if (reaction instanceof MetabolicReaction) { builder.associate(gp).with((MetabolicReaction) reaction); } } } } addEdit(builder.apply()); }
From source file:eu.mondo.driver.mongo.MongoGraphDriver.java
@Override public void insertEdgesWithVertex(final Multimap<String, String> edges, final String edgeURI, final String vertexTypeURI) throws IOException { if (edges.isEmpty()) { return;/*w ww .ja v a 2s .co m*/ } for (final String targetVertexURI : edges.values()) { insertVertex(vertexTypeURI, targetVertexURI); } insertEdges(edges, edgeURI); }
From source file:uk.ac.ebi.mdk.apps.tool.SuggestExchangeMetabolites.java
private Multimap<Long, Metabolite> index(final Set<Metabolite> metabolites) { Multimap<Long, Metabolite> index = HashMultimap.create(metabolites.size(), 2); for (final Metabolite metabolite : metabolites) { for (ChemicalStructure structure : metabolite.getStructures()) { long hashCode = generator.generate(structure.getStructure()); index.put(hashCode, metabolite); }//from w w w . ja v a 2 s . c o m } if (index.isEmpty()) { System.err.println("No metabolites were indexed, do they have strucutres?"); } return index; }
From source file:org.apache.aurora.scheduler.async.preemptor.PreemptorImpl.java
@Override public synchronized Optional<String> findPreemptionSlotFor(final String taskId, AttributeAggregate attributeAggregate) { final Optional<IAssignedTask> pendingTask = fetchIdlePendingTask(taskId); // Task is no longer PENDING no need to preempt. if (!pendingTask.isPresent()) { return Optional.absent(); }/*from www . j a v a 2 s. c om*/ Multimap<String, PreemptionVictim> slavesToActiveTasks = clusterState.getSlavesToActiveTasks(); if (slavesToActiveTasks.isEmpty()) { return Optional.absent(); } attemptedPreemptions.incrementAndGet(); // Group the offers by slave id so they can be paired with active tasks from the same slave. Multimap<String, HostOffer> slavesToOffers = Multimaps.index(offerQueue.getOffers(), OFFER_TO_SLAVE_ID); Set<String> allSlaves = ImmutableSet.<String>builder().addAll(slavesToOffers.keySet()) .addAll(slavesToActiveTasks.keySet()).build(); for (String slaveID : allSlaves) { final Optional<Set<String>> toPreemptTasks = getTasksToPreempt(slavesToActiveTasks.get(slaveID), slavesToOffers.get(slaveID), pendingTask.get(), attributeAggregate); if (toPreemptTasks.isPresent()) { storage.write(new Storage.MutateWork.NoResult.Quiet() { @Override protected void execute(Storage.MutableStoreProvider storeProvider) { for (String toPreempt : toPreemptTasks.get()) { stateManager.changeState(storeProvider, toPreempt, Optional.<ScheduleStatus>absent(), PREEMPTING, Optional.of("Preempting in favor of " + taskId)); tasksPreempted.incrementAndGet(); } } }); return Optional.of(slaveID); } } noSlotsFound.incrementAndGet(); return Optional.absent(); }
From source file:org.sonarlint.intellij.trigger.MakeTrigger.java
private void submitFiles(VirtualFile[] files, String trigger) { Multimap<Module, VirtualFile> filesByModule = HashMultimap.create(); for (VirtualFile file : files) { Module m = ModuleUtil.findModuleForFile(file, myProject); if (!SonarLintUtils.shouldAnalyzeAutomatically(file, m)) { continue; }//from w w w.j a va 2s. c o m filesByModule.put(m, file); } if (!filesByModule.isEmpty()) { console.debug("Trigger: " + trigger); for (Module m : filesByModule.keySet()) { analyzer.submitAsync(m, filesByModule.get(m), TriggerType.COMPILATION); } } }
From source file:org.sosy_lab.cpachecker.cpa.bdd.BddArgBasedRefiner.java
/** * This method performs an value-analysis refinement. * * @param reached the current reached set * @param errorPath the current error path * @returns true, if the value-analysis refinement was successful, else false * @throws CPAException when value-analysis interpolation fails *//*from www. ja va 2 s. c o m*/ private boolean performValueAnalysisRefinement(final ARGReachedSet reached, final ARGPath errorPath) throws CPAException, InterruptedException { numberOfValueAnalysisRefinements++; int currentErrorPathId = errorPath.toString().hashCode(); // same error path as in last iteration -> no progress if (currentErrorPathId == previousErrorPathId) { throw new RefinementFailedException(Reason.RepeatedCounterexample, errorPath); } previousErrorPathId = currentErrorPathId; UnmodifiableReachedSet reachedSet = reached.asReachedSet(); Precision precision = reachedSet.getPrecision(reachedSet.getLastState()); VariableTrackingPrecision bddPrecision = (VariableTrackingPrecision) Precisions.asIterable(precision) .filter(VariableTrackingPrecision.isMatchingCPAClass(BDDCPA.class)).get(0); Multimap<CFANode, MemoryLocation> increment = interpolatingRefiner.determinePrecisionIncrement(errorPath); Pair<ARGState, CFAEdge> refinementRoot = interpolatingRefiner.determineRefinementRoot(errorPath, increment, false); // no increment - value-analysis refinement was not successful if (increment.isEmpty()) { return false; } VariableTrackingPrecision refinedBDDPrecision = bddPrecision.withIncrement(increment); numberOfSuccessfulValueAnalysisRefinements++; reached.removeSubtree(refinementRoot.getFirst(), refinedBDDPrecision, VariableTrackingPrecision.isMatchingCPAClass(BDDCPA.class)); return true; }
From source file:org.lealone.cluster.locator.NetworkTopologyStrategy.java
/** * calculate endpoints in one pass through the tokens by tracking our progress in each DC, rack etc. *///from w ww . j ava 2 s . co m @Override @SuppressWarnings("serial") public List<InetAddress> calculateNaturalEndpoints(Token searchToken, TokenMetaData tokenMetaData) { // we want to preserve insertion order so that the first added endpoint becomes primary Set<InetAddress> replicas = new LinkedHashSet<>(); // replicas we have found in each DC Map<String, Set<InetAddress>> dcReplicas = new HashMap<>(datacenters.size()); for (Map.Entry<String, Integer> dc : datacenters.entrySet()) dcReplicas.put(dc.getKey(), new HashSet<InetAddress>(dc.getValue())); Topology topology = tokenMetaData.getTopology(); // all endpoints in each DC, so we can check when we have exhausted all the members of a DC Multimap<String, InetAddress> allEndpoints = topology.getDatacenterEndpoints(); // all racks in a DC so we can check when we have exhausted all racks in a DC Map<String, Multimap<String, InetAddress>> racks = topology.getDatacenterRacks(); assert !allEndpoints.isEmpty() && !racks.isEmpty() : "not aware of any cluster members"; // tracks the racks we have already placed replicas in Map<String, Set<String>> seenRacks = new HashMap<>(datacenters.size()); for (Map.Entry<String, Integer> dc : datacenters.entrySet()) seenRacks.put(dc.getKey(), new HashSet<String>()); // tracks the endpoints that we skipped over while looking for unique racks // when we relax the rack uniqueness we can append this to the current result // so we don't have to wind back the iterator Map<String, Set<InetAddress>> skippedDcEndpoints = new HashMap<>(datacenters.size()); for (Map.Entry<String, Integer> dc : datacenters.entrySet()) skippedDcEndpoints.put(dc.getKey(), new LinkedHashSet<InetAddress>()); Iterator<Token> tokenIter = TokenMetaData.ringIterator(tokenMetaData.sortedTokens(), searchToken, false); while (tokenIter.hasNext() && !hasSufficientReplicas(dcReplicas, allEndpoints)) { Token next = tokenIter.next(); InetAddress ep = tokenMetaData.getEndpoint(next); String dc = snitch.getDatacenter(ep); // have we already found all replicas for this dc? if (!datacenters.containsKey(dc) || hasSufficientReplicas(dc, dcReplicas, allEndpoints)) continue; // can we skip checking the rack? if (seenRacks.get(dc).size() == racks.get(dc).keySet().size()) { dcReplicas.get(dc).add(ep); replicas.add(ep); } else { String rack = snitch.getRack(ep); // is this a new rack? if (seenRacks.get(dc).contains(rack)) { skippedDcEndpoints.get(dc).add(ep); } else { dcReplicas.get(dc).add(ep); replicas.add(ep); seenRacks.get(dc).add(rack); // if we've run out of distinct racks, add the hosts we skipped past already (up to RF) if (seenRacks.get(dc).size() == racks.get(dc).keySet().size()) { Iterator<InetAddress> skippedIt = skippedDcEndpoints.get(dc).iterator(); while (skippedIt.hasNext() && !hasSufficientReplicas(dc, dcReplicas, allEndpoints)) { InetAddress nextSkipped = skippedIt.next(); dcReplicas.get(dc).add(nextSkipped); replicas.add(nextSkipped); } } } } } return new ArrayList<InetAddress>(replicas); }
From source file:hu.bme.mit.trainbenchmark.benchmark.fourstore.driver.FourStoreDriver.java
public void deleteEdges(final Multimap<String, String> edges, final String type) throws IOException { if (edges.isEmpty()) { return;/*w w w .j ava2s . c om*/ } deleteEdgesPartition(edges, type); }
From source file:org.sonarlint.intellij.actions.SonarAnalyzeScopeAction.java
@Override public void actionPerformed(AnActionEvent e) { Project p = e.getProject();// w ww. jav a2s. c o m if (p == null) { return; } SonarLintConsole console = SonarLintConsole.get(p); IssueTreeScope scope = e.getData(IssueTreeScope.SCOPE_DATA_KEY); if (scope == null) { console.error("No scope found"); return; } Collection<VirtualFile> files = scope.getAll(); if (files.isEmpty()) { console.error("No files for analysis"); return; } Multimap<Module, VirtualFile> filesByModule = HashMultimap.create(); for (VirtualFile file : files) { Module m = ModuleUtil.findModuleForFile(file, p); if (!SonarLintUtils.shouldAnalyze(file, m)) { console.info("File '" + file + "' cannot be analyzed"); continue; } filesByModule.put(m, file); } if (!filesByModule.isEmpty()) { SonarLintJobManager analyzer = SonarLintUtils.get(p, SonarLintJobManager.class); for (Module m : filesByModule.keySet()) { if (executeBackground(e)) { analyzer.submitAsync(m, filesByModule.get(m), TriggerType.ACTION); } else { analyzer.submit(m, filesByModule.get(m), TriggerType.ACTION); } } } }
From source file:com.b2international.snowowl.snomed.datastore.request.IdRequest.java
@Override public R execute(final C context) { final IdActionRecorder recorder = new IdActionRecorder(context); try {/*from w w w . j ava 2 s . c o m*/ final Multimap<ComponentCategory, SnomedComponentCreateRequest> componentCreateRequests = getComponentCreateRequests( next()); if (!componentCreateRequests.isEmpty()) { final Timer idGenerationTimer = context.service(Metrics.class).timer("idGeneration"); try { idGenerationTimer.start(); for (final ComponentCategory category : componentCreateRequests.keySet()) { final Class<? extends SnomedComponentDocument> documentClass = getDocumentClass(category); final Collection<BaseSnomedComponentCreateRequest> categoryRequests = FluentIterable .from(componentCreateRequests.get(category)) .filter(BaseSnomedComponentCreateRequest.class).toSet(); final Set<String> userSuppliedIds = FluentIterable.from(categoryRequests) .filter(request -> request.getIdGenerationStrategy() instanceof ConstantIdStrategy) .transform( request -> ((ConstantIdStrategy) request.getIdGenerationStrategy()).getId()) .toSet(); if (!userSuppliedIds.isEmpty()) { final Set<String> existingIds = getExistingIds(context, userSuppliedIds, documentClass); if (!existingIds.isEmpty()) { throw new AlreadyExistsException(category.getDisplayName(), existingIds); } recorder.register(userSuppliedIds); } final Multimap<String, BaseSnomedComponentCreateRequest> requestsByNamespace = HashMultimap .create(); FluentIterable.from(categoryRequests) .filter(request -> request.getIdGenerationStrategy() instanceof NamespaceIdStrategy) .forEach(request -> { NamespaceIdStrategy strategy = (NamespaceIdStrategy) request .getIdGenerationStrategy(); String namespace = Strings.isNullOrEmpty(strategy.getNamespace()) || SnomedIdentifiers.INT_NAMESPACE.equals(strategy.getNamespace()) ? SnomedIdentifiers.INT_NAMESPACE : strategy.getNamespace(); requestsByNamespace.put(namespace, request); }); Set<BaseSnomedComponentCreateRequest> metadataBasedIdRequests = FluentIterable .from(categoryRequests) .filter(request -> request.getIdGenerationStrategy() instanceof MetadataIdStrategy) .toSet(); if (!metadataBasedIdRequests.isEmpty()) { String namespaceFromMetadata = BranchMetadataResolver.getEffectiveBranchMetadataValue( context.branch(), SnomedCoreConfiguration.BRANCH_DEFAULT_NAMESPACE_KEY); String namespace = Strings.isNullOrEmpty(namespaceFromMetadata) ? SnomedIdentifiers.INT_NAMESPACE : namespaceFromMetadata; metadataBasedIdRequests.forEach(request -> requestsByNamespace.put(namespace, request)); } for (final String namespace : requestsByNamespace.keySet()) { final String convertedNamespace = namespace.equals(SnomedIdentifiers.INT_NAMESPACE) ? null : namespace; final Collection<BaseSnomedComponentCreateRequest> requests = requestsByNamespace .get(namespace); final int count = requests.size(); final Set<String> uniqueIds = getUniqueIds(context, recorder, category, documentClass, count, convertedNamespace); final Iterator<String> idsToUse = Iterators.consumingIterator(uniqueIds.iterator()); for (final BaseSnomedComponentCreateRequest createRequest : requests) { createRequest.setIdGenerationStrategy(new ConstantIdStrategy(idsToUse.next())); } checkState(!idsToUse.hasNext(), "More SNOMED CT ids have been requested than used."); } } } finally { idGenerationTimer.stop(); } } final R commitInfo = next(context); recorder.commit(); return commitInfo; } catch (final Exception e) { recorder.rollback(); throw e; } }