com.google.common.collect.Multimap#put ( )源码实例Demo

下面列出了com.google.common.collect.Multimap#put ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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);
}
 
源代码2 项目: Quicksql   文件: AbstractMaterializedViewRule.java
/**
 * 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;
}
 
源代码3 项目: datawave   文件: CompositeIngest.java
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;
}
 
源代码4 项目: codemining-core   文件: MethodScopeExtractor.java
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;

}
 
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;
}
 
@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());
		}
	}
}
 
源代码7 项目: datawave   文件: ExpandCompositeTermsTest.java
@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);
}
 
源代码8 项目: xtext-extras   文件: RawResolvedFeatures.java
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);
		}
	}
}
 
源代码9 项目: apollo   文件: DefaultRolePermissionService.java
/**
 * 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());
}
 
/**
 * 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;
}
 
源代码11 项目: tracecompass   文件: ResourcesView.java
@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;
}
 
源代码12 项目: Bats   文件: RelMdNodeTypes.java
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;
}
 
源代码13 项目: bundletool   文件: ModuleDependenciesUtils.java
/**
 * 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);
}
 
源代码14 项目: bazel   文件: ImmutableSortedKeyListMultimapTest.java
@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));
}
 
源代码15 项目: incubator-pinot   文件: CallGraphEntity.java
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);
}
 
源代码16 项目: datawave   文件: EventQueryDataDecorator.java
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("@[email protected]", 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;
        }
    }
}
 
源代码17 项目: incubator-pinot   文件: DimensionEntity.java
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;
}
 
源代码18 项目: datawave   文件: EventMapperTest.java
@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);
}
 
源代码19 项目: tracecompass   文件: SystemCall.java
@Override
public Multimap<String, Object> getMetadata() {
    Multimap<String, Object> map = HashMultimap.create();
    map.put(OsStrings.tid(), fTid);
    return map;
}
 
源代码20 项目: buck   文件: APKModuleGraph.java
/**
 * 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;
}