java类com.google.common.collect.ImmutableSetMultimap的实例源码

BrokenDownLinearScoreAggregator.java 文件源码 项目:bue-common-open 阅读 14 收藏 0 点赞 0 评论 0
@Override
public void observeSample(
    final Collection<Map<String, FMeasureCounts>> observationSummaries) {
  final ImmutableSetMultimap.Builder<String, FMeasureCounts> allCountsB =
      ImmutableSetMultimap.builder();

  for (final Map<String, FMeasureCounts> observationSummary : observationSummaries) {
    allCountsB.putAll(Multimaps.forMap(observationSummary));
  }

  for (final Map.Entry<String, Collection<FMeasureCounts>> breakdownKeySamples : allCountsB.build().asMap().entrySet()) {
    double scoreAggregator = 0.0;
    double normalizer = 0.0;

    for (final FMeasureCounts fMeasureCounts : breakdownKeySamples.getValue()) {
      // per-doc scores clipped at 0
      scoreAggregator += Math.max(fMeasureCounts.truePositives()
          - alpha()*fMeasureCounts.falsePositives(), 0);
      normalizer += fMeasureCounts.truePositives() + fMeasureCounts.falseNegatives();
    }
    double normalizedScore = 100.0*scoreAggregator/normalizer;
    linearScoresB.put(breakdownKeySamples.getKey(), normalizedScore);
  }
}
BrokenDownFMeasureAggregator.java 文件源码 项目:bue-common-open 阅读 15 收藏 0 点赞 0 评论 0
@Override
public void observeSample(
    final Collection<Map<String, FMeasureCounts>> observationSummaries) {
  final ImmutableSetMultimap.Builder<String, FMeasureCounts> allCountsB =
      ImmutableSetMultimap.builder();

  for (final Map<String, FMeasureCounts> observationSummary : observationSummaries) {
    allCountsB.putAll(Multimaps.forMap(observationSummary));
  }

  for (final Map.Entry<String, Collection<FMeasureCounts>> aggregate : allCountsB.build().asMap().entrySet()) {
    final FMeasureCounts fMeasureInfo = FMeasureCounts.combineToMicroFMeasure(aggregate.getValue());
    f1sB.put(aggregate.getKey(), fMeasureInfo.F1());
    precisionsB.put(aggregate.getKey(), fMeasureInfo.precision());
    recallsB.put(aggregate.getKey(), fMeasureInfo.recall());
  }
}
AnnotationWrapperModule.java 文件源码 项目:bue-common-open 阅读 16 收藏 0 点赞 0 评论 0
@Value.Check
protected void check() {
  checkArgument(!wrappedModuleParam().isEmpty());

  // check for wrapped module bindings which will collide when we strip their own annotations
  // and replace them with the wrapping annotation
  final ImmutableSetMultimap.Builder<TypeLiteral<?>, Key<?>> externalTypesToInternalTypesB =
      ImmutableSetMultimap.builder();
  for (final Key<?> key : simpleTypesToWrap()) {
    externalTypesToInternalTypesB.put(key.getTypeLiteral(), key);
  }
  final ImmutableSetMultimap<TypeLiteral<?>, Key<?>> externalTypesToInternalTypes =
      externalTypesToInternalTypesB.build();

  for (final Map.Entry<TypeLiteral<?>, Collection<Key<?>>> e : externalTypesToInternalTypes
      .asMap().entrySet()) {
    if (e.getValue().size() > 1) {
      throw new IllegalArgumentException("You are exposing multiple inner module bindings which"
          + " will have the same external binding key: " + e.getValue());
    }
  }
}
Bug8307Test.java 文件源码 项目:yangtools 阅读 16 收藏 0 点赞 0 评论 0
@Test
public void testDeviationsSupportedInSomeModules() throws Exception {
    final SetMultimap<QNameModule, QNameModule> modulesWithSupportedDeviations =
            ImmutableSetMultimap.<QNameModule, QNameModule>builder()
            .put(foo, bar)
            .put(foo, baz)
            .put(bar, baz)
            .build();

    final SchemaContext schemaContext = RFC7950Reactors.defaultReactor().newBuild()
            .addSources(FOO_MODULE, BAR_MODULE, BAZ_MODULE, FOOBAR_MODULE)
            .setModulesWithSupportedDeviations(modulesWithSupportedDeviations)
            .buildEffective();
    assertNotNull(schemaContext);

    assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, myFooContA)));
    assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, myFooContB)));
    assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, myFooContC)));
    assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, myBarContA)));
    assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, myBarContB)));
}
ImmutableMultimapSerializer.java 文件源码 项目:bazel 阅读 15 收藏 0 点赞 0 评论 0
@Override
public ImmutableMultimap<Object, Object> read(
    Kryo kryo, Input input, Class<ImmutableMultimap<Object, Object>> type) {
  ImmutableMultimap.Builder<Object, Object> builder;
  if (type.equals(ImmutableListMultimap.class)) {
    builder = ImmutableListMultimap.builder();
  } else if (type.equals(ImmutableSetMultimap.class)) {
    builder = ImmutableSetMultimap.builder();
  } else {
    builder = ImmutableMultimap.builder();
  }

  @SuppressWarnings("unchecked")
  Map<Object, Collection<Object>> map = kryo.readObject(input, ImmutableMap.class);
  for (Map.Entry<Object, Collection<Object>> entry : map.entrySet()) {
    builder.putAll(entry.getKey(), entry.getValue());
  }
  return builder.build();
}
ZipFilterAction.java 文件源码 项目:bazel 阅读 14 收藏 0 点赞 0 评论 0
@VisibleForTesting
static Multimap<String, Long> getEntriesToOmit(
    Collection<Path> filterZips, Collection<String> filterTypes) throws IOException {
  // Escape filter types to prevent regex abuse
  Set<String> escapedFilterTypes = new HashSet<>();
  for (String filterType : filterTypes) {
    escapedFilterTypes.add(Pattern.quote(filterType));
  }
  // Match any string that ends with any of the filter file types
  String filterRegex = String.format(".*(%s)$", Joiner.on("|").join(escapedFilterTypes));

  ImmutableSetMultimap.Builder<String, Long> entriesToOmit = ImmutableSetMultimap.builder();
  for (Path filterZip : filterZips) {
    try (ZipReader zip = new ZipReader(filterZip.toFile())) {
      for (ZipFileEntry entry : zip.entries()) {
        if (filterTypes.isEmpty() || entry.getName().matches(filterRegex)) {
          entriesToOmit.put(entry.getName(), entry.getCrc());
        }
      }
    }
  }
  return entriesToOmit.build();
}
DefaultJavaLibraryTest.java 文件源码 项目:buck-cutom 阅读 19 收藏 0 点赞 0 评论 0
@Test
public void testEmptySuggestBuildFunction() {
  BuildRuleResolver ruleResolver = new BuildRuleResolver();

  BuildTarget libraryOneTarget = BuildTargetFactory.newInstance("//:libone");
  JavaLibrary libraryOne = (JavaLibrary) JavaLibraryBuilder
      .createBuilder(libraryOneTarget)
      .addSrc(Paths.get("java/src/com/libone/bar.java"))
      .build();

  BuildContext context = createSuggestContext(ruleResolver,
      BuildDependencies.FIRST_ORDER_ONLY);

  ImmutableSetMultimap<JavaLibrary, Path> classpathEntries =
      libraryOne.getTransitiveClasspathEntries();

  assertEquals(
      Optional.<JavacInMemoryStep.SuggestBuildRules>absent(),
      ((DefaultJavaLibrary) libraryOne).createSuggestBuildFunction(
          context,
          classpathEntries,
          classpathEntries,
          createJarResolver(/* classToSymbols */ImmutableMap.<Path, String>of())));

  EasyMock.verify(context);
}
Classpaths.java 文件源码 项目:buck-cutom 阅读 15 收藏 0 点赞 0 评论 0
/**
 * Include the classpath entries from all JavaLibraryRules that have a direct line of lineage
 * to this rule through other JavaLibraryRules. For example, in the following dependency graph:
 *
 *        A
 *      /   \
 *     B     C
 *    / \   / \
 *    D E   F G
 *
 * If all of the nodes correspond to BuildRules that implement JavaLibraryRule except for
 * B (suppose B is a Genrule), then A's classpath will include C, F, and G, but not D and E.
 * This is because D and E are used to generate B, but do not contribute .class files to things
 * that depend on B. However, if C depended on E as well as F and G, then E would be included in
 * A's classpath.
 */
public static ImmutableSetMultimap<JavaLibrary, Path> getClasspathEntries(
    Set<BuildRule> deps) {
  final ImmutableSetMultimap.Builder<JavaLibrary, Path> classpathEntries =
      ImmutableSetMultimap.builder();
  for (BuildRule dep : deps) {
    JavaLibrary library = null;
    if (dep instanceof JavaLibrary) {
      library = (JavaLibrary) dep;
    }

    if (library != null) {
      classpathEntries.putAll(library.getTransitiveClasspathEntries());
    }
  }
  return classpathEntries.build();
}
ReferenceValidatorImpl.java 文件源码 项目:cm_ext 阅读 19 收藏 0 点赞 0 评论 0
@Override
public void beforeNode(Object obj, DescriptorPath path) {
  Preconditions.checkState(!refsStack.containsKey(path));

  SetMultimap<ReferenceType, String> refs = getRelatedPaths(obj, path);
  SetMultimap<ReferenceType, String> newRefs = LinkedHashMultimap.create();

  for (Map.Entry<ReferenceType, Collection<String>> entry : refs.asMap().entrySet()) {
    ReferenceType type = entry.getKey();
    for (String reference : entry.getValue()) {
      if (!allowedRefs.containsEntry(type, reference)) {
        newRefs.put(type, reference);
        allowedRefs.put(type, reference);
      }
    }
  }

  // consolidate into the singleton if it's empty
  newRefs = newRefs.size() == 0 ? ImmutableSetMultimap
      .<ReferenceType, String> of() : newRefs;
  refsStack.put(path, newRefs);

  callReferenceConstraints(obj, path);
}
IvyDependencyMetadata.java 文件源码 项目:Reer 阅读 15 收藏 0 点赞 0 评论 0
public IvyDependencyMetadata(ModuleVersionSelector requested, String dynamicConstraintVersion, boolean force, boolean changing, boolean transitive, Multimap<String, String> confMappings, List<Artifact> artifacts, List<Exclude> excludes) {
    super(requested, artifacts);
    this.dynamicConstraintVersion = dynamicConstraintVersion;
    this.force = force;
    this.changing = changing;
    this.transitive = transitive;
    this.confs = ImmutableSetMultimap.copyOf(confMappings);
    this.excludes = ImmutableList.copyOf(excludes);
}


问题


面经


文章

微信
公众号

扫码关注公众号