Java Code Examples for com.google.common.base.Functions#forMap()

The following examples show how to use com.google.common.base.Functions#forMap() . 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: KBPEATestUtils.java    From tac-kbp-eal with MIT License 6 votes vote down vote up
public static ResponseLinking dummyResponseLinkingFor(EventArgumentLinking linking) {
  final DummyResponseGenerator responseGenerator = new DummyResponseGenerator();
  final Map<TypeRoleFillerRealis, Response> canonicalResponses = Maps.newHashMap();

  final Iterable<TypeRoleFillerRealis> allTRFRs = ImmutableSet.copyOf(
      concat(concat(linking.eventFrames()), linking.incomplete()));

  for (final TypeRoleFillerRealis trfr : allTRFRs) {
    canonicalResponses.put(trfr, responseGenerator.responseFor(trfr));
  }

  final Function<TypeRoleFillerRealis, Response> canonicalResponseFunction =
      Functions.forMap(canonicalResponses);

  final ImmutableSet.Builder<ResponseSet> responseSets = ImmutableSet.builder();
  for (final TypeRoleFillerRealisSet trfrSet : linking.eventFrames()) {
    responseSets.add(ResponseSet.from(transform(trfrSet, canonicalResponseFunction)));
  }
  final Set<Response> incompletes = FluentIterable.from(linking.incomplete())
      .transform(canonicalResponseFunction).toSet();
  return ResponseLinking.builder().docID(linking.docID()).responseSets(responseSets.build())
    .incompleteResponses(incompletes).build();
}
 
Example 2
Source File: TypeMirrors.java    From FreeBuilder with Apache License 2.0 4 votes vote down vote up
Function<String, TypeMirror> asFunction() {
  return Functions.forMap(substitutions);
}
 
Example 3
Source File: PresentSpotRequestsAndInstancesTest.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
@Test
public void testWhenSpotsPresentSingleCall() {

   Function<SpotInstanceRequest, AWSRunningInstance> converter = Functions.forMap(ImmutableMap.of(spot1, instance1,
         spot2, instance2));

   AWSEC2Api client = createMock(AWSEC2Api.class);
   SpotInstanceApi spotApi = createMock(SpotInstanceApi.class);

   expect(client.getSpotInstanceApi()).andReturn((Optional) Optional.of(spotApi));
   expect(spotApi.describeSpotInstanceRequestsInRegion("us-east-1", "sir-aaaa", "sir-bbbb")).andReturn(
         ImmutableSet.of(spot1, spot2));

   replay(client, spotApi);

   PresentSpotRequestsAndInstances fn = new PresentSpotRequestsAndInstances(client, converter);

   assertEquals(fn.apply(ImmutableSet.of(new RegionAndName("us-east-1", "sir-aaaa"), new RegionAndName("us-east-1",
         "sir-bbbb"))), ImmutableSet.of(instance1, instance2));

   verify(client, spotApi);
}
 
Example 4
Source File: DexArchiveAspect.java    From bazel with Apache License 2.0 4 votes vote down vote up
/**
 * Runs Jars in {@link JavaInfo#getDirectRuntimeJars()} through desugaring action if flag is set
 * and adds the result to {@code result}. Note that this cannot happen in a separate aspect
 * because aspects don't see providers added by other aspects executed on the same target.
 */
private Function<Artifact, Artifact> desugarJarsIfRequested(
    ConfiguredTarget base, RuleContext ruleContext, ConfiguredAspect.Builder result) {
  if (!getAndroidConfig(ruleContext).desugarJava8()) {
    return Functions.identity();
  }
  Map<Artifact, Artifact> newlyDesugared = new HashMap<>();
  if (JavaCommon.isNeverLink(ruleContext)) {
    result.addProvider(AndroidRuntimeJarProvider.NEVERLINK);
    return Functions.forMap(newlyDesugared);
  }
  AndroidRuntimeJarProvider.Builder desugaredJars =
      new AndroidRuntimeJarProvider.Builder()
          .addTransitiveProviders(
              collectPrerequisites(ruleContext, AndroidRuntimeJarProvider.class));
  if (isProtoLibrary(ruleContext)) {
    // TODO(b/33557068): Desugar protos if needed instead of assuming they don't need desugaring
    result.addProvider(desugaredJars.build());
    return Functions.identity();
  }

  JavaInfo javaInfo = JavaInfo.getJavaInfo(base);
  if (javaInfo != null) {
    // These are all transitive hjars of dependencies and hjar of the jar itself
    NestedSet<Artifact> compileTimeClasspath =
        getJavaCompilationArgsProvider(base, ruleContext).getTransitiveCompileTimeJars();
    ImmutableSet.Builder<Artifact> jars = ImmutableSet.builder();
    jars.addAll(javaInfo.getDirectRuntimeJars());

    // If the target is an android_library, it may be a Starlark android_library in which case
    // get the R.jar from the AndroidIdeInfoProvider.
    if (isAndroidLibrary(ruleContext)) {
      Artifact rJar = getAndroidLibraryRJar(base);
      if (rJar != null) {
        // TODO(b/124540821): Disable R.jar desugaring (with a flag).
        jars.add(rJar);
      }
    }

    // For android_* targets we need to honor their bootclasspath (nicer in general to do so)
    NestedSet<Artifact> bootclasspath = getBootclasspath(base, ruleContext);

    ImmutableSet<Artifact> jarsToProcess = jars.build();
    boolean basenameClash = checkBasenameClash(jarsToProcess);
    for (Artifact jar : jarsToProcess) {
      Artifact desugared =
          createDesugarAction(
              ruleContext, basenameClash, jar, bootclasspath, compileTimeClasspath);
      newlyDesugared.put(jar, desugared);
      desugaredJars.addDesugaredJar(jar, desugared);
    }
  }
  result.addProvider(desugaredJars.build());
  return Functions.forMap(newlyDesugared);
}
 
Example 5
Source File: FakeProcessExecutor.java    From buck with Apache License 2.0 4 votes vote down vote up
public FakeProcessExecutor(Map<ProcessExecutorParams, FakeProcess> processMap, Console console) {
  this(Functions.forMap(processMap), console);
}
 
Example 6
Source File: FakeListeningProcessExecutor.java    From buck with Apache License 2.0 4 votes vote down vote up
public FakeListeningProcessExecutor(
    Multimap<ProcessExecutorParams, FakeListeningProcessState> processStates) {
  this(Functions.forMap(processStates.asMap()), SettableFakeClock.DO_NOT_CARE);
}
 
Example 7
Source File: FakeListeningProcessExecutor.java    From buck with Apache License 2.0 4 votes vote down vote up
public FakeListeningProcessExecutor(
    Multimap<ProcessExecutorParams, FakeListeningProcessState> processStates,
    SettableFakeClock clock) {
  this(Functions.forMap(processStates.asMap()), clock);
}