Java Code Examples for com.google.common.collect.Multimap#put()
The following examples show how to use
com.google.common.collect.Multimap#put() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractPackageJSONValidatorExtension.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Collects all key-path-value pairs that can be extracted from the given {@code object} and stores them in * {@code documentValues}. * * Key-paths are represented in terms of concatenated strings, separated by a {@code .} character (e.g. * "nested.name.value" => JSONValue). * * @param object * The {@link JSONObject} to collect the values form. * @param documentValues * The map to store the values to. * @param prefix * The prefix to use for key-paths. * @param depth * The depth up to which the given {@link JSONObject} should be traversed. If {@code -1} no depth limit * is assumed. */ private Multimap<String, JSONValue> collectDocumentValues(JSONObject object, Multimap<String, JSONValue> documentValues, String prefix, int depth) { // If maximum depth has been reached, do not traverse object further. // For negative depths this will always evaluate to false -> no depth limit if (depth == 0) { return documentValues; } for (NameValuePair pair : object.getNameValuePairs()) { final String pairName = pair.getName(); final String name = prefix.isEmpty() ? pairName : prefix + "." + pairName; final JSONValue value = pair.getValue(); documentValues.put(name, value); if (value instanceof JSONObject) { // recursively collect all values from pair value collectDocumentValues((JSONObject) value, documentValues, name, depth - 1); } } return documentValues; }
Example 2
Source File: CSVThirdEyeDataSourceTest.java From incubator-pinot with Apache License 2.0 | 6 votes |
@Test public void testExecuteGroupByTimeGranularityAndColumns() throws Exception { Multimap<String, String> filter = ArrayListMultimap.create(); filter.put("country", "cn"); ThirdEyeRequest request = ThirdEyeRequest.newBuilder() .addMetricFunction(new MetricFunction(MetricAggFunction.SUM, "views", 1L, "source", null, null)) .setDataSource("source") .setGroupByTimeGranularity(new TimeGranularity(1, TimeUnit.HOURS)) .addGroupBy(Arrays.asList("country", "browser")) .build("ref"); ThirdEyeResponse expectedResponse = new CSVThirdEyeResponse( request, new TimeSpec("timestamp", new TimeGranularity(1, TimeUnit.HOURS), TimeSpec.SINCE_EPOCH_FORMAT), new DataFrame() .addSeries("timestamp", 0, 3600000, 7200000, 10800000, 0, 3600000, 7200000, 10800000) .addSeries("country", "us", "us","us","us", "cn", "cn","cn","cn") .addSeries("browser", "chrome", "chrome", "chrome", "chrome", "chrome", "chrome", "chrome", "safari") .addSeries("SUM_views", 1088, 1001, 1002, 1003, 2000, 2001, 2002, 2003) ); ThirdEyeResponse response = dataSource.execute(request); Assert.assertEquals(response, expectedResponse); }
Example 3
Source File: AbstractMaterializedViewRule.java From Quicksql with MIT License | 6 votes |
/** * Given the source and target equivalence classes, it extracts the possible mappings * from each source equivalence class to each target equivalence class. * * <p>If any of the source equivalence classes cannot be mapped to a target equivalence * class, it returns null. */ private static Multimap<Integer, Integer> extractPossibleMapping( List<Set<RexTableInputRef>> sourceEquivalenceClasses, List<Set<RexTableInputRef>> targetEquivalenceClasses) { Multimap<Integer, Integer> mapping = ArrayListMultimap.create(); for (int i = 0; i < targetEquivalenceClasses.size(); i++) { boolean foundQueryEquivalenceClass = false; final Set<RexTableInputRef> viewEquivalenceClass = targetEquivalenceClasses.get(i); for (int j = 0; j < sourceEquivalenceClasses.size(); j++) { final Set<RexTableInputRef> queryEquivalenceClass = sourceEquivalenceClasses.get(j); if (queryEquivalenceClass.containsAll(viewEquivalenceClass)) { mapping.put(j, i); foundQueryEquivalenceClass = true; break; } } // end for if (!foundQueryEquivalenceClass) { // Target equivalence class not found in source equivalence class return null; } } // end for return mapping; }
Example 4
Source File: DefaultRolePermissionService.java From apollo with Apache License 2.0 | 6 votes |
/** * Create permissions, note that permissionType + targetId should be unique */ @Transactional public Set<Permission> createPermissions(Set<Permission> permissions) { Multimap<String, String> targetIdPermissionTypes = HashMultimap.create(); for (Permission permission : permissions) { targetIdPermissionTypes.put(permission.getTargetId(), permission.getPermissionType()); } for (String targetId : targetIdPermissionTypes.keySet()) { Collection<String> permissionTypes = targetIdPermissionTypes.get(targetId); List<Permission> current = permissionRepository.findByPermissionTypeInAndTargetId(permissionTypes, targetId); Preconditions.checkState(CollectionUtils.isEmpty(current), "Permission with permissionType %s targetId %s already exists!", permissionTypes, targetId); } Iterable<Permission> results = permissionRepository.saveAll(permissions); return StreamSupport.stream(results.spliterator(), false).collect(Collectors.toSet()); }
Example 5
Source File: CompositeIngest.java From datawave with Apache License 2.0 | 6 votes |
public Multimap<String,NormalizedContentInterface> normalizeMap(Multimap<String,NormalizedContentInterface> eventFields) { Multimap<String,NormalizedContentInterface> compositeFields = HashMultimap.create(); if (this.compiledFieldPatterns == null) compilePatterns(); if (this.compositeToFieldMap != null && !this.compositeToFieldMap.isEmpty()) { List<NormalizedContentInterface> tempResults = new ArrayList<>(); for (String compositeField : this.compositeToFieldMap.keySet()) { tempResults.clear(); addCompositeFields(tempResults, eventFields, compositeField, null, null, GroupingPolicy.IGNORE_GROUPS, allowMissing.get(compositeField), this.compositeToFieldMap.get(compositeField).toArray(new String[0]), 0, new StringBuilder(), new StringBuilder(), null, CompositeIngest.isOverloadedCompositeField(this.compositeToFieldMap, compositeField)); for (NormalizedContentInterface value : tempResults) { compositeFields.put(value.getIndexedFieldName(), value); } } } return compositeFields; }
Example 6
Source File: MethodScopeExtractor.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static Multimap<Scope, String> getScopeSnippets(final ASTNode node, final boolean methodAsRoots) { final ScopeFinder scopeFinder = new ScopeFinder(methodAsRoots); node.accept(scopeFinder); final Multimap<Scope, String> scopes = TreeMultimap.create(); for (final Entry<ASTNode, Method> method : scopeFinder.methods .entries()) { scopes.put(new Scope(method.getKey().toString(), method.getValue().type, METHOD_CALL, 0, 0), method .getValue().name); } return scopes; }
Example 7
Source File: NodeJSServerCodegen.java From TypeScript-Microservices with MIT License | 6 votes |
private static List<Map<String, Object>> sortOperationsByPath(List<CodegenOperation> ops) { Multimap<String, CodegenOperation> opsByPath = ArrayListMultimap.create(); for (CodegenOperation op : ops) { opsByPath.put(op.path, op); } List<Map<String, Object>> opsByPathList = new ArrayList<Map<String, Object>>(); for (Entry<String, Collection<CodegenOperation>> entry : opsByPath.asMap().entrySet()) { Map<String, Object> opsByPathEntry = new HashMap<String, Object>(); opsByPathList.add(opsByPathEntry); opsByPathEntry.put("path", entry.getKey()); opsByPathEntry.put("operation", entry.getValue()); List<CodegenOperation> operationsForThisPath = Lists.newArrayList(entry.getValue()); operationsForThisPath.get(operationsForThisPath.size() - 1).hasMore = false; if (opsByPathList.size() < opsByPath.asMap().size()) { opsByPathEntry.put("hasMore", "true"); } } return opsByPathList; }
Example 8
Source File: RawResolvedFeatures.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected void computeAllFeatures( JvmDeclaredType type, String name, Multimap<String, AbstractResolvedOperation> processedOperations, Set<String> processedFields, List<JvmFeature> result) { Iterable<JvmFeature> features = type.findAllFeaturesByName(name); for(JvmFeature feature: features) { if (feature instanceof JvmOperation) { JvmOperation operation = (JvmOperation) feature; String simpleName = operation.getSimpleName(); if (processedOperations.containsKey(simpleName)) { if (isOverridden(operation, processedOperations.get(simpleName))) { continue; } } BottomResolvedOperation resolvedOperation = createResolvedOperation(operation); processedOperations.put(simpleName, resolvedOperation); result.add(operation); } else if (feature instanceof JvmField && processedFields.add(feature.getSimpleName())) { result.add(feature); } } }
Example 9
Source File: InteractiveUnresolvedTypeResolver.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public void resolve(TypeUsages typeUsages, XtextResource resource) { if(typeUsages.getUnresolvedTypeUsages().isEmpty() || resource == null) return; Multimap<String, TypeUsage> name2usage = LinkedHashMultimap.create(); for (TypeUsage unresolved : typeUsages.getUnresolvedTypeUsages()) { String text = unresolved.getUsedTypeName(); text = nameValueConverter.toValue(text, null); name2usage.put(text, unresolved); } for (String name : name2usage.keySet()) { Iterable<TypeUsage> usages = name2usage.get(name); JvmDeclaredType resolvedType = resolve(name, usages, resource); if (resolvedType != null) { for (TypeUsage usage : usages) typeUsages.addTypeUsage( resolvedType, usage.getSuffix(), usage.getTextRegion(), usage.getContext()); } } }
Example 10
Source File: ExpandCompositeTermsTest.java From datawave with Apache License 2.0 | 6 votes |
@Test public void test12() throws Exception { ShardQueryConfiguration conf = new ShardQueryConfiguration(); Multimap<String,String> compositeToFieldMap = LinkedListMultimap.create(); compositeToFieldMap.put("GEO", "GEO"); compositeToFieldMap.put("GEO", "WKT_BYTE_LENGTH"); conf.setCompositeToFieldMap(compositeToFieldMap); Map<String,String> compositeToSeparatorMap = new HashMap<>(); compositeToSeparatorMap.put("GEO", ","); conf.setCompositeFieldSeparators(compositeToSeparatorMap); Set<String> indexedFields = new HashSet<>(); indexedFields.add("GEO"); conf.getFieldToDiscreteIndexTypes().put("GEO", new GeometryType()); String query = "((GEO >= '1f0155640000000000' && GEO <= '1f01556bffffffffff') || GEO == '00' || (GEO >= '0100' && GEO <= '0103')) && (WKT_BYTE_LENGTH >= '" + Normalizer.NUMBER_NORMALIZER.normalize("0") + "' && WKT_BYTE_LENGTH <= '" + Normalizer.NUMBER_NORMALIZER.normalize("12345") + "')"; String expected = "(((GEO >= '1f0155640000000000,+AE0' && GEO <= '1f01556bffffffffff,+eE1.2345') && ((ASTEvaluationOnly = true) && ((GEO >= '1f0155640000000000' && GEO <= '1f01556bffffffffff') && (WKT_BYTE_LENGTH >= '+AE0' && WKT_BYTE_LENGTH <= '+eE1.2345')))) || ((GEO >= '00,+AE0' && GEO <= '00,+eE1.2345') && ((ASTEvaluationOnly = true) && (GEO == '00' && (WKT_BYTE_LENGTH >= '+AE0' && WKT_BYTE_LENGTH <= '+eE1.2345')))) || ((GEO >= '0100,+AE0' && GEO <= '0103,+eE1.2345') && ((ASTEvaluationOnly = true) && ((GEO >= '0100' && GEO <= '0103') && (WKT_BYTE_LENGTH >= '+AE0' && WKT_BYTE_LENGTH <= '+eE1.2345')))))"; runTestQuery(query, expected, indexedFields, conf); }
Example 11
Source File: ResourcesView.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override protected @NonNull Multimap<@NonNull Integer, @NonNull String> getRegexes() { Multimap<@NonNull Integer, @NonNull String> regexes = super.getRegexes(); if (!fFollowedThread.isEmpty()) { regexes.put(IFilterProperty.BOUND, fFollowedThread); } else { regexes.removeAll(IFilterProperty.BOUND); } return regexes; }
Example 12
Source File: DimensionEntity.java From incubator-pinot with Apache License 2.0 | 5 votes |
public static Multimap<String, String> makeFilterSet(Set<DimensionEntity> entities) { Multimap<String, String> filters = ArrayListMultimap.create(); for (DimensionEntity e : entities) { if (TYPE_PROVIDED.equals(e.getType())) { filters.put(e.name, e.value); } } return filters; }
Example 13
Source File: EventQueryDataDecorator.java From datawave with Apache License 2.0 | 5 votes |
public void decorateData(Multimap<String,FieldBase> data) { // Get the values for the FieldName to put the decorated data into Collection<FieldBase> destinationOfData = data.get(fieldName); // Loop over all decorator patterns for (Map.Entry<String,String> entry : this.patternMap.entrySet()) { // Find fieldNames which match the current pattern Collection<FieldBase> collectionSourceOfData = data.get(entry.getKey()); if (collectionSourceOfData != null && !collectionSourceOfData.isEmpty()) { // multiple value source fields for the substitution value not supported -- use the first one Iterator<FieldBase> collectionSourceItr = collectionSourceOfData.iterator(); FieldBase sourceOfData = collectionSourceItr.next(); Map<String,String> markings = sourceOfData.getMarkings(); String id = sourceOfData.getValueString(); String newValue = entry.getValue().replace("@field_value@", id); // If we have no values for the decorated data's field name if (destinationOfData == null || destinationOfData.size() < 1) { // Add the result data.put(fieldName, this.makeField(fieldName, sourceOfData.getMarkings(), sourceOfData.getColumnVisibility(), sourceOfData.getTimestamp(), newValue)); } else { // Otherwise, find the original data for (FieldBase dest : destinationOfData) { // Update that Value's value (destinationOfData changes the underlying Multimap) dest.setValue(newValue); } } // attempt to use a multiple value source field if (collectionSourceItr.hasNext()) { log.info("EventQueryDataDecorator configured to use a source field: " + entry.getKey() + " with multiple values -- using the first"); } break; } } }
Example 14
Source File: CallGraphEntity.java From incubator-pinot with Apache License 2.0 | 5 votes |
public static CallGraphEntity fromEdge(double score, List<? extends Entity> related, DataFrame edge) { if (edge.size() != 1) { throw new IllegalArgumentException("Must provide a data frame with exactly one row"); } Multimap<String, String> dimensions = ArrayListMultimap.create(); for (String seriesName : edge.getSeriesNames()) { dimensions.put(seriesName, edge.getString(seriesName, 0)); } return new CallGraphEntity(TYPE.formatURN(EntityUtils.encodeDimensions(dimensions)), score, related, edge); }
Example 15
Source File: ImmutableSortedKeyListMultimapTest.java From bazel with Apache License 2.0 | 5 votes |
@Test public void builderPutNullValue() { Multimap<String, Integer> toPut = LinkedListMultimap.create(); toPut.put(null, 1); ImmutableSortedKeyListMultimap.Builder<String, Integer> builder = ImmutableSortedKeyListMultimap.builder(); assertThrows(NullPointerException.class, () -> builder.put("foo", null)); assertThrows( NullPointerException.class, () -> builder.putAll("foo", Arrays.asList(1, null, 3))); assertThrows(NullPointerException.class, () -> builder.putAll("foo", 1, null, 3)); assertThrows(NullPointerException.class, () -> builder.putAll(toPut)); }
Example 16
Source File: ModuleDependenciesUtils.java From bundletool with Apache License 2.0 | 5 votes |
/** * Builds a map of module dependencies. * * <p>If module "a" contains {@code <uses-split name="b"/>} manifest entry, then the map contains * entry ("a", "b"). * * <p>All modules implicitly depend on the "base" module. Hence the map contains also dependency * ("base", "base"). */ public static Multimap<String, String> buildAdjacencyMap(ImmutableList<BundleModule> modules) { Multimap<String, String> moduleDependenciesMap = ArrayListMultimap.create(); for (BundleModule module : modules) { String moduleName = module.getName().getName(); AndroidManifest manifest = module.getAndroidManifest(); checkArgument( !moduleDependenciesMap.containsKey(moduleName), "Module named '%s' was passed in multiple times.", moduleName); moduleDependenciesMap.putAll(moduleName, manifest.getUsesSplits()); // Check that module does not declare explicit dependency on the "base" module // (whose split ID actually is empty instead of "base" anyway). if (moduleDependenciesMap.containsEntry(moduleName, BASE_MODULE_NAME.getName())) { throw InvalidBundleException.builder() .withUserMessage( "Module '%s' declares dependency on the '%s' module, which is implicit.", moduleName, BASE_MODULE_NAME) .build(); } // Add implicit dependency on the base. Also ensures that every module has a key in the map. moduleDependenciesMap.put(moduleName, BASE_MODULE_NAME.getName()); } return Multimaps.unmodifiableMultimap(moduleDependenciesMap); }
Example 17
Source File: RelMdNodeTypes.java From Bats with Apache License 2.0 | 5 votes |
private static Multimap<Class<? extends RelNode>, RelNode> getNodeTypes(RelNode rel, Class<? extends RelNode> c, RelMetadataQuery mq) { final Multimap<Class<? extends RelNode>, RelNode> nodeTypeCount = ArrayListMultimap.create(); for (RelNode input : rel.getInputs()) { Multimap<Class<? extends RelNode>, RelNode> partialNodeTypeCount = mq.getNodeTypes(input); if (partialNodeTypeCount == null) { return null; } nodeTypeCount.putAll(partialNodeTypeCount); } nodeTypeCount.put(c, rel); return nodeTypeCount; }
Example 18
Source File: SystemCall.java From tracecompass with Eclipse Public License 2.0 | 4 votes |
@Override public Multimap<String, Object> getMetadata() { Multimap<String, Object> map = HashMultimap.create(); map.put(OsStrings.tid(), fTid); return map; }
Example 19
Source File: EventMapperTest.java From datawave with Apache License 2.0 | 4 votes |
@Before public void setUp() throws Exception { long eventTime = System.currentTimeMillis(); eventMapper = new EventMapper<>(); conf = new Configuration(); conf.setClass(EventMapper.CONTEXT_WRITER_CLASS, TestContextWriter.class, ContextWriter.class); Type type = new Type("file", null, null, new String[] {SimpleDataTypeHandler.class.getName()}, 10, null); Type errorType = new Type(TypeRegistry.ERROR_PREFIX, null, null, new String[] {SimpleDataTypeHandler.class.getName()}, 20, null); TypeRegistry registry = TypeRegistry.getInstance(conf); registry.put(type.typeName(), type); registry.put(errorType.typeName(), errorType); Multimap<String,NormalizedContentInterface> fields = HashMultimap.create(); fields.put("fileExtension", new BaseNormalizedContent("fileExtension", "gz")); fields.put("lastModified", new BaseNormalizedContent("lastModified", "2016-01-01")); SimpleDataTypeHelper.registerFields(fields); record = new SimpleRawRecord(); record.setRawFileTimestamp(eventTime); record.setDataType(type); record.setDate(eventTime); record.setRawFileName("/some/filename"); record.setRawData("some data".getBytes()); record.generateId(null); errorRecord = new SimpleRawRecord(); errorRecord.setRawFileTimestamp(0); errorRecord.setDataType(type); errorRecord.setDate(eventTime); errorRecord.setRawFileName("/some/filename"); errorRecord.setRawData("some data".getBytes()); errorRecord.generateId(null); errorRecord.setRawFileName(""); errorRecord.addError("EVENT_DATE_MISSING"); errorRecord.setFatalError(true); expect(mapContext.getConfiguration()).andReturn(conf).anyTimes(); mapContext.progress(); expectLastCall().anyTimes(); TestContextWriter<BulkIngestKey,Value> testContextWriter = new TestContextWriter<>(); mapContext.write(anyObject(BulkIngestKey.class), anyObject(Value.class)); expectLastCall().andDelegateTo(testContextWriter).anyTimes(); expect(mapContext.getInputSplit()).andReturn(null); expect(mapContext.getMapOutputValueClass()).andReturn(null); StandaloneTaskAttemptContext standaloneContext = new StandaloneTaskAttemptContext(conf, new StandaloneStatusReporter()); expect(mapContext.getCounter(anyObject())).andDelegateTo(standaloneContext).anyTimes(); expect(mapContext.getCounter(anyString(), anyString())).andDelegateTo(standaloneContext).anyTimes(); replay(mapContext); }
Example 20
Source File: APKModuleGraph.java From buck with Apache License 2.0 | 4 votes |
/** * For each seed target, find its reachable targets and mark them in a multimap as being reachable * by that module for later sorting into exclusive and shared targets * * @return the Multimap containing targets and the seed modules that contain them */ private Multimap<BuildTarget, String> mapTargetsToContainingModules() { Multimap<BuildTarget, String> targetToContainingApkModuleNameMap = MultimapBuilder.treeKeys().treeSetValues().build(); for (Map.Entry<String, ImmutableList<BuildTarget>> seedConfig : getSeedConfigMap().get().entrySet()) { String seedModuleName = seedConfig.getKey(); for (BuildTarget seedTarget : seedConfig.getValue()) { targetToContainingApkModuleNameMap.put(seedTarget, seedModuleName); new AbstractBreadthFirstTraversal<TargetNode<?>>(targetGraph.get(seedTarget)) { @Override public ImmutableSet<TargetNode<?>> visit(TargetNode<?> node) { ImmutableSet.Builder<TargetNode<?>> depsBuilder = ImmutableSet.builder(); for (BuildTarget depTarget : node.getBuildDeps()) { if (!isInRootModule(depTarget) && !isSeedTarget(depTarget)) { depsBuilder.add(targetGraph.get(depTarget)); targetToContainingApkModuleNameMap.put(depTarget, seedModuleName); } } return depsBuilder.build(); } }.start(); } } // Now to generate the minimal covers of APKModules for each set of APKModules that contain // a buildTarget DirectedAcyclicGraph<String> declaredDependencies = getDeclaredDependencyGraph(); Multimap<BuildTarget, String> targetModuleEntriesToRemove = MultimapBuilder.treeKeys().treeSetValues().build(); for (BuildTarget key : targetToContainingApkModuleNameMap.keySet()) { Collection<String> modulesForTarget = targetToContainingApkModuleNameMap.get(key); new AbstractBreadthFirstTraversal<String>(modulesForTarget) { @Override public Iterable<String> visit(String moduleName) throws RuntimeException { Collection<String> dependentModules = declaredDependencies.getIncomingNodesFor(moduleName); for (String dependent : dependentModules) { if (modulesForTarget.contains(dependent)) { targetModuleEntriesToRemove.put(key, dependent); } } return dependentModules; } }.start(); } for (Map.Entry<BuildTarget, String> entryToRemove : targetModuleEntriesToRemove.entries()) { targetToContainingApkModuleNameMap.remove(entryToRemove.getKey(), entryToRemove.getValue()); } return targetToContainingApkModuleNameMap; }