List of usage examples for com.google.common.collect Multimap entries
Collection<Map.Entry<K, V>> entries();
From source file:org.onehippo.cms7.essentials.rest.PluginResource.java
@ApiOperation(value = "Return a list of changes made by the plugin during setup, given certain parameter values.", notes = "[API] Messages are only indication what might change, because operations may be skipped, " + "e.g. file copy is not executed if file already exists.", response = RestfulList.class) @ApiParam(name = PLUGIN_ID, value = "Plugin ID", required = true) @POST//from ww w .ja v a2 s .c om @Path("/{" + PLUGIN_ID + "}/changes") public RestfulList<MessageRestful> getInstructionPackageChanges(@PathParam(PLUGIN_ID) final String pluginId, final PostPayloadRestful payload) throws Exception { final RestfulList<MessageRestful> list = new RestfulList<>(); final Plugin plugin = pluginStore.getPluginById(pluginId); if (plugin == null) { list.add(new ErrorMessageRestful("Setup Changes: Plugin with ID '" + pluginId + "' was not found.")); return list; } final InstructionPackage instructionPackage = plugin.makeInstructionPackageInstance(); if (instructionPackage == null) { list.add(new ErrorMessageRestful("Failed to create instructions package")); return list; } final Map<String, String> values = payload.getValues(); final Map<String, Object> properties = new HashMap<String, Object>(values); instructionPackage.setProperties(properties); final PluginContext context = PluginContextFactory.getContext(); context.addPlaceholderData(properties); @SuppressWarnings("unchecked") final Multimap<MessageGroup, MessageRestful> messages = (Multimap<MessageGroup, MessageRestful>) instructionPackage .getInstructionsMessages(context); final Collection<Map.Entry<MessageGroup, MessageRestful>> entries = messages.entries(); for (Map.Entry<MessageGroup, MessageRestful> entry : entries) { final MessageRestful value = entry.getValue(); value.setGroup(entry.getKey()); value.setGlobalMessage(false); list.add(value); } return list; }
From source file:fr.ujm.tse.lt2c.satin.triplestore.VerticalPartioningTripleStoreRWLock.java
@Override public Collection<Triple> getbySubject(final long s) { this.rwlock.readLock().lock(); final Collection<Triple> result = new ArrayList<>(this.triples); try {/*from w ww. j av a2 s .co m*/ for (final Long predicate : this.internalstore.keySet()) { final Multimap<Long, Long> multimap = this.internalstore.get(predicate); if (multimap == null) { continue; } for (final Entry<Long, Long> entry : multimap.entries()) { if (entry.getKey() == s) { result.add(new ImmutableTriple(entry.getKey(), predicate, entry.getValue())); } } } } catch (final Exception e) { logger.error("", e); } finally { this.rwlock.readLock().unlock(); } return result; }
From source file:fr.ujm.tse.lt2c.satin.triplestore.VerticalPartioningTripleStoreRWLock.java
@Override public Collection<Triple> getbyObject(final long o) { this.rwlock.readLock().lock(); final Collection<Triple> result = new ArrayList<>(this.triples); try {/*from w ww. ja va 2 s .c om*/ for (final Long predicate : this.internalstore.keySet()) { final Multimap<Long, Long> multimap = this.internalstore.get(predicate); if (multimap == null) { continue; } for (final Entry<Long, Long> entry : multimap.entries()) { if (entry.getValue() == o) { result.add(new ImmutableTriple(entry.getKey(), predicate, entry.getValue())); } } } } catch (final Exception e) { logger.error("", e); } finally { this.rwlock.readLock().unlock(); } return result; }
From source file:rabbit.data.internal.xml.access.AbstractAccessor.java
/** * Gets the data from the XML files./*from w ww . ja va 2 s . c o m*/ * * @param start The start date of the data to get. * @param end The end date of the data to get. * @return The data between the dates, inclusive. */ private Multimap<WorkspaceStorage, S> getXmlData(LocalDate start, LocalDate end) { XMLGregorianCalendar startDate = toXmlDate(start); XMLGregorianCalendar endDate = toXmlDate(end); XmlPlugin plugin = XmlPlugin.getDefault(); IPath[] storagePaths = plugin.getStoragePaths(); Multimap<WorkspaceStorage, S> data = LinkedListMultimap.create(storagePaths.length); Multimap<WorkspaceStorage, File> files = LinkedListMultimap.create(storagePaths.length); for (IPath storagePath : storagePaths) { List<File> fileList = getDataStore().getDataFiles(start, end, storagePath); IPath workspacePath = plugin.getWorkspacePath(storagePath); files.putAll(new WorkspaceStorage(storagePath, workspacePath), fileList); } for (Map.Entry<WorkspaceStorage, File> entry : files.entries()) { for (S list : getCategories(getDataStore().read(entry.getValue()))) { XMLGregorianCalendar date = list.getDate(); if (date == null) { continue; // Ignore invalid data. } if (startDate.compare(date) <= 0 && date.compare(endDate) <= 0) { data.put(entry.getKey(), list); } } } return data; }
From source file:hu.bme.mit.trainbenchmark.benchmark.fourstore.driver.FourStoreDriver.java
protected void edgesToTriples(final Multimap<String, String> edges, final String edgeLabel, final StringBuilder insertQueryBuilder) { boolean first = true; for (final Entry<String, String> edge : edges.entries()) { if (first) { first = false;//from www . jav a 2 s . co m } else { insertQueryBuilder.append("."); } final String sourceVertex = edge.getKey(); final String targetVertex = edge.getValue(); insertQueryBuilder.append(String.format(" %s %s %s ", brackets(sourceVertex), brackets(edgeLabel), brackets(targetVertex))); } }
From source file:org.robotframework.ide.eclipse.main.plugin.project.build.validation.KeywordSettingsValidator.java
private void reportArgumentsDefaultValuesUnknownVariables() { for (final KeywordArguments argSetting : keyword.getArguments()) { final Set<String> definedVariables = newHashSet(validationContext.getAccessibleVariables()); for (final RobotToken argToken : argSetting.getArguments()) { final boolean hasDefault = argToken.getText().contains("="); if (hasDefault) { final List<String> splitted = Splitter.on('=').limit(2).splitToList(argToken.getText()); final String def = splitted.get(0); final String unifiedDefinitionName = VariableNamesSupport.extractUnifiedVariableName(def); final Multimap<String, RobotToken> usedVariables = VariableNamesSupport.extractUnifiedVariables( newArrayList(argToken), new VariableExtractor(), validationContext.getFile().getName()); for (final Entry<String, RobotToken> entry : usedVariables.entries()) { if (isInvalidVariableDeclaration(definedVariables, unifiedDefinitionName, entry)) { final RobotProblem problem = RobotProblem .causedBy(VariablesProblem.UNDECLARED_VARIABLE_USE) .formatMessageWith(entry.getValue().getText()); final Map<String, Object> additional = ImmutableMap .<String, Object>of(AdditionalMarkerAttributes.NAME, entry.getKey()); reporter.handleProblem(problem, validationContext.getFile(), entry.getValue(), additional); }/* w w w . ja va 2s. com*/ } definedVariables.add(unifiedDefinitionName); } else { definedVariables.add(VariableNamesSupport.extractUnifiedVariableName(argToken.getText())); } } } }
From source file:com.google.devtools.build.lib.skyframe.PrepareAnalysisPhaseFunction.java
private LinkedHashSet<TargetAndConfiguration> resolveConfigurations(SkyFunction.Environment env, Iterable<TargetAndConfiguration> nodes, Multimap<BuildConfiguration, Dependency> asDeps) throws InterruptedException { Map<Label, Target> labelsToTargets = new LinkedHashMap<>(); for (TargetAndConfiguration node : nodes) { labelsToTargets.put(node.getTarget().getLabel(), node.getTarget()); }// w w w. j a v a2 s . c o m // Maps <target, originalConfig> pairs to <target, finalConfig> pairs for targets that // could be successfully Skyframe-evaluated. Map<TargetAndConfiguration, TargetAndConfiguration> successfullyEvaluatedTargets = new LinkedHashMap<>(); for (BuildConfiguration fromConfig : asDeps.keySet()) { Multimap<Dependency, BuildConfiguration> trimmedTargets = getConfigurations(env, fromConfig.getOptions(), asDeps.get(fromConfig)); if (trimmedTargets == null) { continue; } for (Map.Entry<Dependency, BuildConfiguration> trimmedTarget : trimmedTargets.entries()) { Target target = labelsToTargets.get(trimmedTarget.getKey().getLabel()); successfullyEvaluatedTargets.put(new TargetAndConfiguration(target, fromConfig), new TargetAndConfiguration(target, trimmedTarget.getValue())); } } if (env.valuesMissing()) { return null; } LinkedHashSet<TargetAndConfiguration> result = new LinkedHashSet<>(); for (TargetAndConfiguration originalNode : nodes) { if (successfullyEvaluatedTargets.containsKey(originalNode)) { // The configuration was successfully trimmed. result.add(successfullyEvaluatedTargets.get(originalNode)); } else { // Either the configuration couldn't be determined (e.g. loading phase error) or it's null. result.add(originalNode); } } return result; }
From source file:eumetsat.pn.solr.webapp.SolrApp.java
@Override protected Map<String, Object> search(String searchTerms, String filterString, int from, int size) { Map<String, Object> data = new HashMap<>(); // put "session" parameters here rightaway so it can be used in template even when empty result data.put("search_terms", searchTerms == null ? "*:*" : searchTerms); data.put("filter_terms", filterString == null ? "" : filterString); Stopwatch stopwatch = Stopwatch.createStarted(); try {/* w w w . j av a 2s. c o m*/ SolrQuery query = new SolrQuery(); query.setQuery(searchTerms); query.setStart(from == -1 ? 0 : from); query.setRows(size); query.setFields("id", "title", "description", "thumbnail_s", "status_s", "score"); // "exclude" xmldoc query.setParam("qt", "edismax"); // probably default already // boosting query.setParam("qf", "title^10 description status^2 keywords"); // set highlight, see also https://cwiki.apache.org/confluence/display/solr/Standard+Highlighter query.setHighlight(true).setHighlightSnippets(17).setHighlightFragsize(0); // http://wiki.apache.org/solr/HighlightingParameters query.setParam("hl.preserveMulti", "true"); // preserve non-matching keywords query.setParam("hl.fl", "id", "title", "description", "keywords"); // "*"); // select fields to highlight // override defaults: query.setParam("hl.simple.pre", "<em><strong>"); query.setParam("hl.simple.post", "</strong></em>"); // configure faceting, see also http://wiki.apache.org/solr/SolrFacetingOverview and http://wiki.apache.org/solr/Solrj and https://wiki.apache.org/solr/SimpleFacetParameters and query.setFacet(true).setFacetLimit(4).setFacetMissing(true); // not in API, probably normally set in schema.xml: query.setParam("facet.field", "satellite_s", "instrument_s", "category", "societalBenefitArea_ss", "distribution_ss"); // filtering Set<String> hiddenFacets = new HashSet<>(); // hiding no facets yet if (filterString != null && !filterString.isEmpty()) { Multimap<String, String> filterTermsMap = parseFiltersTerms(filterString); if (filterTermsMap.size() > 0) { for (Map.Entry<String, String> entry : filterTermsMap.entries()) { String filter = " +" + entry.getKey() + ":" + entry.getValue(); query.addFilterQuery(filter); hiddenFacets.add(entry.getKey() + ":" + entry.getValue()); } } } data.put("tohide", hiddenFacets); log.debug("Solr query: {}", query); QueryResponse response = solr.query(query); if (response == null) { log.error("Response from {} is null!", this.name); data.put("total_hits", 0); data = addMessage(data, MessageLevel.danger, "Response is null from " + this.name); } else { log.trace("Got response: {}", response); if (response.getStatus() == 0) { List<Map<String, Object>> resHits = new ArrayList<>(); SolrDocumentList results = response.getResults(); Map<String, Map<String, List<String>>> highlights = response.getHighlighting(); data.put("total_hits", results.getNumFound()); if (results.getNumFound() < 1) { addMessage(data, MessageLevel.info, "No results found!"); } data.put("max_score", results.getMaxScore()); Map<String, Object> pagination = computePaginationParams( ((Long) (data.get("total_hits"))).intValue(), from); data.put("pagination", pagination); for (SolrDocument result : results) { HashMap<String, Object> resHit = new HashMap<>(); String currentId = (String) result.getFieldValue("id"); Map<String, List<String>> currentHighlights = highlights.get(currentId); resHit.put("id", currentId); resHit.put("score", String.format("%.4g", result.getFieldValue("score"))); resHit.put("abstract", hightlightIfGiven(result, currentHighlights, "description")); resHit.put("title", hightlightIfGiven(result, currentHighlights, "title")); resHit.put("keywords", Joiner.on(", ").join( (Collection<String>) hightlightIfGiven(result, currentHighlights, "keywords"))); resHit.put("satellite", result.get("satellite_s")); resHit.put("thumbnail", result.get("thumbnail_s")); resHit.put("status", result.get("status_s")); resHit.put("distribution", result.get("distribution_ss")); resHits.add(resHit); } data.put("hits", resHits); // faceting information: List<FacetField> facets = response.getFacetFields(); log.trace("Facets ({}): {}", facets.size(), facets); //jsObj.get("facets").get("categories").get("terms") - then term und count // convert to format of Elasticsearch: Map<String, Object> facetsJson = new HashMap<>(); for (FacetField facet : facets) { Map<String, Object> facetMap = new HashMap<>(); facetMap.put("total", facet.getValueCount()); List<Map<String, Object>> terms = new ArrayList<>(); for (Count count : facet.getValues()) { if (count.getCount() > 0) { Map<String, Object> termMap = new HashMap<>(); termMap.put("count", count.getCount()); termMap.put("term", count.getName() == null ? "N/A" : count.getName()); terms.add(termMap); } } facetMap.put("terms", terms); facetsJson.put(facet.getName(), facetMap); } data.put("facets", facetsJson); } else { // non-OK resonse log.error("Received non-200 response: {}", response); data = addMessage(data, MessageLevel.danger, "Non 200 response: " + response.toString()); } } data.put("elapsed", (double) (stopwatch.elapsed(TimeUnit.MILLISECONDS)) / (double) 1000); log.trace("Prepared data for template: {}", data); } catch (SolrServerException e) { log.error("Error querying Solr", e); addMessage(data, MessageLevel.danger, "Error during search: " + e.getMessage()); // errorResponse(e); } stopwatch.stop(); return data; }
From source file:com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService.java
@Override public void delete(String tableName, Multimap<Cell, Long> keys) { ConcurrentSkipListMap<Key, byte[]> table = getTableMap(tableName).entries; for (Map.Entry<Cell, Long> e : keys.entries()) { table.remove(new Key(e.getKey(), e.getValue())); }/* ww w. j av a 2s . co m*/ }
From source file:org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacade.java
private void handleMisssingInstancesOnTransaction(ConfigTransactionClient ta, ConfigExecution execution) throws DocumentedException { for (Multimap<String, ModuleElementDefinition> modulesToResolved : execution.getModulesDefinition(ta) .values()) {//from www . j a v a 2s . co m for (Map.Entry<String, ModuleElementDefinition> moduleToResolved : modulesToResolved.entries()) { String moduleName = moduleToResolved.getKey(); ModuleElementDefinition moduleElementDefinition = moduleToResolved.getValue(); EditConfigStrategy strategy = moduleElementDefinition.getEditStrategy(); strategy.executeConfiguration(moduleName, moduleElementDefinition.getInstanceName(), null, ta, execution.getServiceRegistryWrapper(ta)); } } }