List of usage examples for com.google.common.collect HashMultimap create
public static <K, V> HashMultimap<K, V> create()
From source file:org.opentestsystem.delivery.testadmin.scheduling.ScheduleTestStatusCreatorImpl.java
@Override public HashMultimap<String, String> findStatusesByStudents(Set<String> studentIds) { List<TestStatus> statuses = testStatusService.findByStudentIds(studentIds); HashMultimap<String, String> studentAssessmentsToFilter = HashMultimap.create(); for (TestStatus status : statuses) { if (status.getOpportunity() == 1 && status.getStatus().equals(Status.SCHEDULED)) { studentAssessmentsToFilter.put(status.getStudentId(), status.getAssessmentId()); }/* w w w .ja v a2s .co m*/ } return studentAssessmentsToFilter; }
From source file:org.semanticweb.elk.proofs.browser.InferenceSetTreeComponent.java
public InferenceSetTreeComponent(final GenericInferenceSet<C, ? extends JustifiedInference<C, A>> inferenceSet, final C conclusion, final TreeNodeLabelProvider nodeDecorator, final TreeNodeLabelProvider toolTipProvider) { this.inferenceSet_ = inferenceSet; this.conclusion_ = conclusion; this.nodeDecorator_ = nodeDecorator; this.toolTipProvider_ = toolTipProvider; this.visibleNodes_ = HashMultimap.create(); setModel(new TreeModelInferenceSetAdapter()); setEditable(true);//from w w w. j a va 2 s . c om final TreeCellRenderer renderer = new TreeCellRenderer(); renderer.setLeafIcon(null); renderer.setOpenIcon(null); renderer.setClosedIcon(null); setCellRenderer(renderer); // JTree does not delegate ToolTip to tree cells otherwise. ToolTipManager.sharedInstance().registerComponent(this); resetVisibleNodes(); // Need to know what will be visible before it gets displayed. addTreeWillExpandListener(new TreeWillExpandListener() { @Override public void treeWillExpand(final TreeExpansionEvent event) throws ExpandVetoException { final TreePath path = event.getPath(); final Object parent = path.getLastPathComponent(); final int count = getModel().getChildCount(parent); for (int i = 0; i < count; i++) { final Object child = getModel().getChild(parent, i); if (!(child instanceof JustifiedInference)) { visibleNodes_.put(child, path.pathByAddingChild(child)); } } } @Override public void treeWillCollapse(final TreeExpansionEvent event) throws ExpandVetoException { final TreePath path = event.getPath(); final Object parent = path.getLastPathComponent(); final int count = getModel().getChildCount(parent); for (int i = 0; i < count; i++) { final Object child = getModel().getChild(parent, i); if (!(child instanceof JustifiedInference)) { visibleNodes_.remove(child, path.pathByAddingChild(child)); } } } }); addMouseListener(new MouseAdapter() { @Override public void mousePressed(final MouseEvent e) { final TreePath path = getPathForLocation(e.getX(), e.getY()); if (path == null) { return; } if (e.getClickCount() == 2) { if (isExpanded(path)) { // TODO: collapse all children } else { expandAll(path); } } } }); }
From source file:ome.services.query.HierarchyNavigatorWrap.java
/** * Batch bulk database queries to prime the cache for {@link #doLookup(Object, Object)}. * It is not necessary to call this method, but it is advised if many lookups are anticipated. * Wraps {@link HierarchyNavigator#prepareLookups(String, String, Collection)}. * @param toType the type of the objects to which the query objects may be related, not <code>null</code> * @param from the query objects, none <code>null</code>, may be of differing types */// ww w .j av a 2 s. com public void prepareLookups(T toType, Collection<E> from) { final String toTypeAsString = typeToString(toType); final SetMultimap<String, Long> fromIdsByType = HashMultimap.create(); for (final E entity : from) { final Map.Entry<String, Long> fromAsStringLong = entityToStringLong(entity); fromIdsByType.put(fromAsStringLong.getKey(), fromAsStringLong.getValue()); } for (final String fromTypeAsString : fromIdsByType.keySet()) { final Set<Long> fromIdsAsLongs = fromIdsByType.get(fromTypeAsString); prepareLookups(toTypeAsString, fromTypeAsString, fromIdsAsLongs); } }
From source file:com.b2international.snowowl.core.internal.validation.ValidationRepositoryContext.java
void commit() { if (!newObjects.isEmpty() || !objectsToDelete.isEmpty()) { final Set<String> ruleIdsAffectedByDeletion = Sets.newHashSet(); service(ValidationRepository.class).write(writer -> { writer.putAll(newObjects);// w w w .java2 s . c o m final Multimap<String, ComponentIdentifier> addToWhitelist = HashMultimap.create(); newObjects.values().stream().filter(ValidationWhiteList.class::isInstance) .map(ValidationWhiteList.class::cast).forEach(whitelist -> addToWhitelist .put(whitelist.getRuleId(), whitelist.getComponentIdentifier())); if (!addToWhitelist.isEmpty()) { ExpressionBuilder filter = Expressions.builder(); for (String ruleId : addToWhitelist.keySet()) { filter.should(Expressions.builder() .filter(Expressions.exactMatch(ValidationIssue.Fields.RULE_ID, ruleId)) .filter(Expressions.matchAny(ValidationIssue.Fields.AFFECTED_COMPONENT_ID, addToWhitelist.get(ruleId).stream().map(ComponentIdentifier::getComponentId) .collect(Collectors.toSet()))) .build()); } writer.bulkUpdate( new BulkUpdate<>(ValidationIssue.class, filter.build(), ValidationIssue.Fields.ID, ValidationIssue.Scripts.WHITELIST, ImmutableMap.of("whitelisted", true))); } final Multimap<String, ComponentIdentifier> removeFromWhitelist = HashMultimap.create(); ValidationRequests.whiteList().prepareSearch().all() .filterByIds(ImmutableSet.copyOf(objectsToDelete.get(ValidationWhiteList.class))).build() .execute(this).forEach(whitelist -> removeFromWhitelist.put(whitelist.getRuleId(), whitelist.getComponentIdentifier())); if (!removeFromWhitelist.isEmpty()) { ExpressionBuilder filter = Expressions.builder(); for (String ruleId : removeFromWhitelist.keySet()) { ruleIdsAffectedByDeletion.add(ruleId); filter.should(Expressions.builder() .filter(Expressions.exactMatch(ValidationIssue.Fields.RULE_ID, ruleId)) .filter(Expressions.matchAny(ValidationIssue.Fields.AFFECTED_COMPONENT_ID, removeFromWhitelist.get(ruleId).stream() .map(ComponentIdentifier::getComponentId) .collect(Collectors.toSet()))) .build()); } writer.bulkUpdate( new BulkUpdate<>(ValidationIssue.class, filter.build(), ValidationIssue.Fields.ID, ValidationIssue.Scripts.WHITELIST, ImmutableMap.of("whitelisted", false))); } final Map<Class<?>, Set<String>> docsToDelete = newHashMap(); objectsToDelete.asMap().forEach((type, ids) -> docsToDelete.put(type, ImmutableSet.copyOf(ids))); writer.removeAll(docsToDelete); writer.commit(); return null; }); if (!newObjects.isEmpty()) { final Set<String> addedWhiteLists = newHashSet(); final Set<String> affectedRuleIds = newHashSet(); newObjects.forEach((id, doc) -> { if (doc instanceof ValidationWhiteList) { ValidationWhiteList whitelistedDoc = (ValidationWhiteList) doc; affectedRuleIds.add(whitelistedDoc.getRuleId()); addedWhiteLists.add(id); } }); if (!addedWhiteLists.isEmpty()) { WhiteListNotification.added(addedWhiteLists, affectedRuleIds).publish(service(IEventBus.class)); } } if (!objectsToDelete.isEmpty()) { final Set<String> removedWhiteLists = ImmutableSet .copyOf(objectsToDelete.get(ValidationWhiteList.class)); if (!removedWhiteLists.isEmpty()) { WhiteListNotification.removed(removedWhiteLists, ruleIdsAffectedByDeletion) .publish(service(IEventBus.class)); } } } }
From source file:com.graphhopper.reader.gtfs.MultiCriteriaLabelSetting.java
MultiCriteriaLabelSetting(GraphExplorer explorer, Weighting weighting, boolean reverse, double maxWalkDistancePerLeg, double maxTransferDistancePerLeg, boolean mindTransfers, int maxVisitedNodes) { this.weighting = (PtTravelTimeWeighting) weighting; this.flagEncoder = (PtFlagEncoder) weighting.getFlagEncoder(); this.maxVisitedNodes = maxVisitedNodes; this.explorer = explorer; this.reverse = reverse; this.maxWalkDistancePerLeg = maxWalkDistancePerLeg; this.maxTransferDistancePerLeg = maxTransferDistancePerLeg; this.mindTransfers = mindTransfers; fromHeap = new PriorityQueue<>(new Comparator<Label>() { @Override/*from w ww .jav a 2 s. c o m*/ public int compare(Label o1, Label o) { return Long.compare(queueCriterion(o1), queueCriterion(o)); } @Override public boolean equals(Object obj) { return false; } }); fromMap = HashMultimap.create(); }
From source file:com.vmware.photon.controller.common.zookeeper.ZookeeperServerSet.java
/** * Creates new ZK server backed by the children of a particular zNode for services. *//*from www. ja v a2s . com*/ @AssistedInject public ZookeeperServerSet(@ServicePathCacheFactory PathChildrenCacheFactory childrenCacheFactory, CuratorFramework zkClient, @ServiceReader ZookeeperServerReader reader, @Assisted("serviceName") String serviceName, @Assisted boolean subscribeToUpdates) throws Exception { this.zkClient = zkClient; this.reader = reader; this.serviceName = serviceName; this.listeners = new HashSet<>(); this.servers = HashMultimap.create(); if (subscribeToUpdates) { needToPopulateServers = false; ThreadFactory threadFactory = new ThreadFactoryBuilder() .setNameFormat("ZkServerSetPathChildrenCache" + "-%d").setDaemon(true).build(); executor = Executors.newSingleThreadExecutor(threadFactory); childrenCache = childrenCacheFactory.create(serviceName, executor); childrenCache.getListenable().addListener(this); } else { needToPopulateServers = true; executor = null; childrenCache = null; } }
From source file:org.eclipse.incquery.validation.runtime.ValidationUtil.java
private static synchronized Multimap<String, Constraint<IPatternMatch>> loadConstraintsFromExtensions() { Multimap<String, Constraint<IPatternMatch>> result = HashMultimap.create(); IExtensionRegistry reg = Platform.getExtensionRegistry(); IExtensionPoint ep = reg.getExtensionPoint("org.eclipse.incquery.validation.runtime.constraint"); for (IExtension extension : ep.getExtensions()) { for (IConfigurationElement ce : extension.getConfigurationElements()) { if (ce.getName().equals("constraint")) { processConstraintConfigurationElement(result, ce); }/* w ww .j av a2 s . c o m*/ } } return result; }
From source file:eu.project.ttc.engines.morpho.PrefixSplitter.java
@Override public void collectionProcessComplete() throws AnalysisEngineProcessException { LOGGER.info("Starting {} for TermIndex {}", TASK_NAME, termIndexResource.getTermIndex().getName()); Multimap<String, Term> lemmaIndex = HashMultimap.create(); int nb = 0;/*from www . j a v a2 s.c om*/ String prefixExtension, lemma, pref; for (Term swt : termIndexResource.getTermIndex().getTerms()) { if (!swt.isSingleWord()) continue; else { lemmaIndex.put(swt.getLemma(), swt); } } for (Term swt : termIndexResource.getTermIndex().getTerms()) { if (!swt.isSingleWord()) continue; Word word = swt.getWords().get(0).getWord(); lemma = word.getLemma(); pref = prefixTree.getPrefix(lemma); if (pref != null && pref.length() < lemma.length()) { prefixExtension = lemma.substring(pref.length(), lemma.length()); if (LOGGER.isTraceEnabled()) LOGGER.trace("Found prefix: {} for word {}", pref, lemma); if (checkIfMorphoExtensionInCorpus) { if (!lemmaIndex.containsKey(prefixExtension)) { if (LOGGER.isTraceEnabled()) LOGGER.trace( "Prefix extension: {} for word {} is not found in corpus. Aborting composition for this word.", prefixExtension, lemma); continue; } else { for (Term target : lemmaIndex.get(prefixExtension)) { watch(swt, target); swt.addTermVariation(target, VariationType.IS_PREFIX_OF, TermSuiteConstants.EMPTY_STRING); } } } nb++; } } LOGGER.debug("Number of words with prefix composition: {} out of {}", nb, termIndexResource.getTermIndex().getWords().size()); }
From source file:com.cinchapi.concourse.example.bank.ConcourseAccount.java
/** * This constructor creates a new record in Concourse and inserts the data * expressed in the parameters./*from w ww .ja v a2 s. c o m*/ * * @param balance the initial balance for the account * @param owners {@link Customer customers} that are owners on the account */ public ConcourseAccount(double balance, Customer... owners) { Preconditions.checkArgument(balance > 0); Concourse concourse = Constants.CONCOURSE_CONNECTIONS.request(); try { Multimap<String, Object> data = HashMultimap.create(); data.put(CLASS_KEY_NAME, getClass().getName()); data.put("balance", balance); for (Customer owner : owners) { data.put("owners", Link.to(owner.getId())); } this.id = concourse.insert(data); // The #insert method is atomic, // so we don't need a transaction // to safely commit all the data } finally { Constants.CONCOURSE_CONNECTIONS.release(concourse); } }
From source file:org.apache.cassandra.dht.BootStrapper.java
public void bootstrap() throws IOException { if (logger.isDebugEnabled()) logger.debug("Beginning bootstrap process"); final Multimap<String, Map.Entry<InetAddress, Collection<Range>>> rangesToFetch = HashMultimap.create(); int requests = 0; for (String table : DatabaseDescriptor.getNonSystemTables()) { Map<InetAddress, Collection<Range>> workMap = getWorkMap(getRangesWithSources(table)).asMap(); for (Map.Entry<InetAddress, Collection<Range>> entry : workMap.entrySet()) { requests++;//from w w w . java 2 s . c om rangesToFetch.put(table, entry); } } final CountDownLatch latch = new CountDownLatch(requests); for (final String table : rangesToFetch.keySet()) { /* Send messages to respective folks to stream data over to me */ for (Map.Entry<InetAddress, Collection<Range>> entry : rangesToFetch.get(table)) { final InetAddress source = entry.getKey(); Collection<Range> ranges = entry.getValue(); final Runnable callback = new Runnable() { public void run() { latch.countDown(); if (logger.isDebugEnabled()) logger.debug(String.format("Removed %s/%s as a bootstrap source; remaining is %s", source, table, latch.getCount())); } }; if (logger.isDebugEnabled()) logger.debug( "Bootstrapping from " + source + " ranges " + StringUtils.join(entry.getValue(), ", ")); StreamIn.requestRanges(source, table, entry.getValue(), callback, OperationType.BOOTSTRAP); } } try { latch.await(); StorageService.instance.finishBootstrapping(); } catch (InterruptedException e) { throw new AssertionError(e); } }