com.google.common.collect.ImmutableList#forEach ( )源码实例Demo

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

@Test public void testValidFiltersForArrow() {
    ImmutableList<Filter> validFilters = ImmutableList.of(
            EqualTo.apply("foo", "manatee"),
            GreaterThan.apply("foo", "aardvark"),
            GreaterThanOrEqual.apply("bar", 2),
            LessThan.apply("foo", "zebra"),
            LessThanOrEqual.apply("bar", 1),
            In.apply("foo", new Object[] {1, 2, 3}),
            IsNull.apply("foo"),
            IsNotNull.apply("foo"),
            And.apply(IsNull.apply("foo"), IsNotNull.apply("bar")),
            Not.apply(IsNull.apply("foo")),
            StringStartsWith.apply("foo", "abc"),
            StringEndsWith.apply("foo", "def"),
            StringContains.apply("foo", "abcdef")
    );
    validFilters.forEach(f -> assertThat(SparkFilterUtils.unhandledFilters(ARROW, f)).isEmpty());
}
 
源代码2 项目: bazel   文件: OrderedClassFileResourceProvider.java
public OrderedClassFileResourceProvider(
    ImmutableList<ClassFileResourceProvider> bootclasspathProviders,
    ImmutableList<ClassFileResourceProvider> classfileProviders) {
  final Set<String> bootclasspathDescriptors = Sets.newHashSet();
  for (ClassFileResourceProvider provider : classfileProviders) {
    // Collect all descriptors provided and the first provider providing each.
    bootclasspathProviders.forEach(p -> bootclasspathDescriptors.addAll(p.getClassDescriptors()));
    for (String descriptor : provider.getClassDescriptors()) {
      // Pick first definition of classpath class and filter out platform classes
      // from classpath if present.
      if (!bootclasspathDescriptors.contains(descriptor)
          && descriptors.add(descriptor)) {
        descriptorToProvider.put(descriptor, provider);
      }
    }
  }
}
 
源代码3 项目: buck   文件: PipelinedModernBuildRule.java
@Override
public final ImmutableList<? extends Step> getPipelinedBuildSteps(
    BuildContext context, BuildableContext buildableContext, State state) {
  ImmutableList.Builder<Path> outputsBuilder = ImmutableList.builder();
  recordOutputs(outputsBuilder::add);
  ImmutableList<Path> outputs = outputsBuilder.build();
  outputs.forEach(buildableContext::recordArtifact);
  OutputPathResolver outputPathResolver = getOutputPathResolver();
  ImmutableList.Builder<Step> stepsBuilder = ImmutableList.builder();
  ModernBuildRule.getSetupStepsForBuildable(
      context, getProjectFilesystem(), outputs, stepsBuilder, outputPathResolver);
  stepsBuilder.addAll(
      getBuildable()
          .getPipelinedBuildSteps(
              context,
              getProjectFilesystem(),
              state,
              outputPathResolver,
              getBuildCellPathFactory(context, getProjectFilesystem(), outputPathResolver)));
  return stepsBuilder.build();
}
 
源代码4 项目: bazel   文件: WorkerSpawnStrategyTest.java
@Test
public void expandArgumentsPreservesEmptyLines() throws Exception {
  File flagfile = folder.newFile("flagfile.txt");

  ImmutableList<String> flags = ImmutableList.of("--hello", "", "--world");

  try (PrintWriter pw = new PrintWriter(Files.newBufferedWriter(flagfile.toPath(), UTF_8))) {
    flags.forEach(pw::println);
  }

  Path execRoot = fs.getPath(folder.getRoot().getAbsolutePath());
  WorkRequest.Builder requestBuilder = WorkRequest.newBuilder();
  WorkerSpawnRunner.expandArgument(execRoot, "@flagfile.txt", requestBuilder);

  assertThat(requestBuilder.getArgumentsList()).containsExactlyElementsIn(flags);
}
 
源代码5 项目: bundletool   文件: BundleToolMain.java
/** Displays a general help. */
public static void help() {
  ImmutableList<CommandHelp> commandHelps =
      ImmutableList.of(
          BuildBundleCommand.help(),
          BuildApksCommand.help(),
          ExtractApksCommand.help(),
          GetDeviceSpecCommand.help(),
          InstallApksCommand.help(),
          InstallMultiApksCommand.help(),
          ValidateBundleCommand.help(),
          DumpCommand.help(),
          GetSizeCommand.help(),
          VersionCommand.help());

  System.out.println("Synopsis: bundletool <command> ...");
  System.out.println();
  System.out.println("Use 'bundletool help <command>' to learn more about the given command.");
  System.out.println();
  commandHelps.forEach(commandHelp -> commandHelp.printSummary(System.out));
}
 
源代码6 项目: james-project   文件: FilteringAggregate.java
public List<? extends Event> defineRules(List<Rule> rules) {
    Preconditions.checkArgument(shouldNotContainDuplicates(rules));
    ImmutableList<RuleSetDefined> events = ImmutableList.of(
        new RuleSetDefined(aggregateId, history.getNextEventId(), ImmutableList.copyOf(rules)));
    events.forEach(this::apply);
    return events;
}
 
源代码7 项目: karate-grpc   文件: DynamicClient.java
private ListenableFuture<Void> callBidiStreaming(
        ImmutableList<DynamicMessage> requests,
        StreamObserver<DynamicMessage> responseObserver,
        CallOptions callOptions) {
    DoneObserver<DynamicMessage> doneObserver = new DoneObserver<>();
    StreamObserver<DynamicMessage> requestObserver = ClientCalls.asyncBidiStreamingCall(
            createCall(callOptions),
            ComponentObserver.of(responseObserver, doneObserver));
    requests.forEach(requestObserver::onNext);
    requestObserver.onCompleted();
    return doneObserver.getCompletionFuture();
}
 
源代码8 项目: karate-grpc   文件: DynamicClient.java
private ListenableFuture<Void> callClientStreaming(
        ImmutableList<DynamicMessage> requests,
        StreamObserver<DynamicMessage> responseObserver,
        CallOptions callOptions) {
    DoneObserver<DynamicMessage> doneObserver = new DoneObserver<>();
    StreamObserver<DynamicMessage> requestObserver = ClientCalls.asyncClientStreamingCall(
            createCall(callOptions),
            ComponentObserver.of(responseObserver, doneObserver));
    requests.forEach(requestObserver::onNext);
    requestObserver.onCompleted();
    return doneObserver.getCompletionFuture();
}
 
源代码9 项目: buck   文件: PerfManifestCommand.java
private static ImmutableMap<BuildRule, ImmutableSet<SourcePath>> getInputsAfterBuildingLocally(
    CommandRunnerParams params,
    ActionGraphBuilder graphBuilder,
    ImmutableList<BuildRule> rulesInGraph) {
  ImmutableMap.Builder<BuildRule, ImmutableSet<SourcePath>> usedInputs = ImmutableMap.builder();

  rulesInGraph.forEach(
      rule -> {
        if (rule instanceof SupportsDependencyFileRuleKey
            && ((SupportsDependencyFileRuleKey) rule).useDependencyFileRuleKeys()) {
          try {
            usedInputs.put(
                rule,
                ImmutableSet.copyOf(
                    ((SupportsDependencyFileRuleKey) rule)
                        .getInputsAfterBuildingLocally(
                            BuildContext.of(
                                graphBuilder.getSourcePathResolver(),
                                params.getCells().getRootCell().getRoot().getPath(),
                                params.getJavaPackageFinder(),
                                params.getBuckEventBus(),
                                false),
                            params.getCells().getRootCell().getCellPathResolver())));
          } catch (Exception e) {
            throw new BuckUncheckedExecutionException(
                e, "When asking %s for its inputs.", rule.getBuildTarget());
          }
        }
      });
  return usedInputs.build();
}
 
源代码10 项目: bundletool   文件: ZipPath.java
public static ZipPath create(ImmutableList<String> names) {
  names.forEach(
      name -> {
        checkArgument(
            !name.contains("/"),
            "Name '%s' contains a forward slash and cannot be used in a path.",
            name);
        checkArgument(
            !FORBIDDEN_NAMES.contains(name), "Name '%s' is not supported inside path.", name);
      });
  return new AutoValue_ZipPath(names);
}
 
源代码11 项目: GitToolBox   文件: ReschedulingExecutor.java
@Override
public void dispose() {
  if (!active.get()) {
    ImmutableList<Future<?>> existingTasks = ImmutableList.copyOf(tasks.values());
    tasks.clear();
    existingTasks.forEach(task -> task.cancel(mayInterrupt));
  }
}
 
源代码12 项目: nomulus   文件: IcannReportingStager.java
/** Creates and stores a manifest file on GCS, indicating which reports were generated. */
void createAndUploadManifest(String subdir, ImmutableList<String> filenames) throws IOException {
  String reportBucketname = String.format("%s/%s", reportingBucket, subdir);
  final GcsFilename gcsFilename = new GcsFilename(reportBucketname, MANIFEST_FILE_NAME);
  StringBuilder manifestString = new StringBuilder();
  filenames.forEach((filename) -> manifestString.append(filename).append("\n"));
  gcsUtils.createFromBytes(gcsFilename, manifestString.toString().getBytes(UTF_8));
  logger.atInfo().log("Wrote %d filenames to manifest at %s", filenames.size(), gcsFilename);
}
 
源代码13 项目: buck   文件: ModernBuildRule.java
@Override
public final ImmutableList<Step> getBuildSteps(
    BuildContext context, BuildableContext buildableContext) {
  ImmutableList.Builder<Path> outputsBuilder = ImmutableList.builder();
  recordOutputs(outputsBuilder::add);
  ImmutableList<Path> outputs = outputsBuilder.build();
  outputs.forEach(buildableContext::recordArtifact);
  return stepsForBuildable(context, buildable, getProjectFilesystem(), getBuildTarget(), outputs);
}
 
源代码14 项目: buck   文件: AuditModulesCommand.java
private static void dumpModuleInformationInRawFormat(
    Console console, ImmutableList<AuditModuleInformation> modules) {

  modules.forEach(module -> dumpModuleInformationInRawFormat(console.getStdOut(), module));
}
 
源代码15 项目: buck   文件: OutputsMaterializer.java
private void processFetchAndMaterialize() {
  ImmutableList.Builder<PendingMaterialization> builder = ImmutableList.builder();
  int size = 0;
  int items = 0;
  while (!waitingMaterialization.isEmpty()) {
    PendingMaterialization data = waitingMaterialization.poll();
    if (data == null) {
      break;
    }
    if (items == 0 || (data.digest.getSize() + size < sizeLimit)) {
      builder.add(data);
      size += data.digest.getSize();
      items++;
    } else {
      waitingMaterialization.addFirst(data);
      break;
    }
  }
  ImmutableList<PendingMaterialization> pending = builder.build();

  if (!pending.isEmpty()) {
    try (SimplePerfEvent.Scope ignored =
        SimplePerfEvent.scope(
            buckEventBus,
            SimplePerfEvent.PerfEventId.of("outputs-materializer"),
            "size",
            size,
            "items",
            pending.size())) {
      if (size > sizeLimit) {
        LOG.debug("Starting stream request for: " + pending.size() + " requests, size: " + size);
        PendingMaterialization large = Iterables.getOnlyElement(pending);

        // Download large files as a stream
        WritableByteChannel channel =
            large.materializer.getOutputChannel(large.path, large.isExecutable);
        ListenableFuture<Unit> fetchToStream = fetcher.fetchToStream(large.digest, channel);
        try {
          // Wait for the stream to finish downloading before picking up more work
          large.future.setFuture(fetchToStream);
          fetchToStream.get();
        } finally {
          tryCloseChannel(channel);
        }
      } else {
        LOG.debug("Starting batch request for: " + pending.size() + " items, size: " + size);
        // Download batches of small objects
        ImmutableMultimap.Builder<Digest, Callable<WritableByteChannel>> digestMap =
            ImmutableMultimap.builder();
        ImmutableMultimap.Builder<Digest, SettableFuture<Unit>> futureMap =
            ImmutableMultimap.builder();
        for (PendingMaterialization p : pending) {
          digestMap.put(p.digest, () -> p.materializer.getOutputChannel(p.path, p.isExecutable));
          futureMap.put(p.digest, p.future);
        }

        ImmutableMultimap<Digest, Callable<WritableByteChannel>> batch = digestMap.build();
        ImmutableMultimap<Digest, SettableFuture<Unit>> futures = futureMap.build();
        fetcher.batchFetchBlobs(batch, futures).get();
      }
      LOG.debug("Finished materializing: " + pending.size() + " requests, size: " + size);
    } catch (Exception e) {
      pending.forEach(materialization -> materialization.future.setException(e));
    }
  }

  if (!waitingMaterialization.isEmpty()) {
    materializerService.submit(this::processFetchAndMaterialize);
  }
}
 
源代码16 项目: luna   文件: ObjectDefinitionFileParser.java
@Override
public void onCompleted(ImmutableList<ObjectDefinition> tokenObjects) throws Exception {
    tokenObjects.forEach(ObjectDefinition.ALL::storeDefinition);
}
 
源代码17 项目: intellij   文件: CompilerWrapperProviderImpl.java
@Override
public File createCompilerExecutableWrapper(
    File executionRoot, File blazeCompilerExecutableFile) {
  try {
    File blazeCompilerWrapper =
        FileUtil.createTempFile("blaze_compiler", ".sh", true /* deleteOnExit */);
    if (!blazeCompilerWrapper.setExecutable(true)) {
      logger.warn("Unable to make compiler wrapper script executable: " + blazeCompilerWrapper);
      return null;
    }
    ImmutableList<String> compilerWrapperScriptLines =
        ImmutableList.of(
            "#!/bin/bash",
            "",
            "# The c toolchain compiler wrapper script doesn't handle arguments files, so we",
            "# need to move the compiler arguments from the file to the command line. We",
            "# preserve any existing commandline arguments, and remove the escaping from",
            "# arguments inside the args file.",
            "",
            "parsedargs=()",
            "for arg in \"${@}\"; do ",
            "  case \"$arg\" in",
            "    @*)",
            "      # Make sure the file ends with a newline - the read loop will not return",
            "      # the final line if it does not.",
            "      echo >> ${arg#@}",
            "      # Args file, the read will remove a layer of escaping",
            "      while read; do",
            "        parsedargs+=($REPLY)",
            "      done < ${arg#@}",
            "      ;;",
            "    *)",
            "      # Regular arg",
            "      parsedargs+=(\"$arg\")",
            "      ;;",
            "  esac",
            "done",
            "",
            "# The actual compiler wrapper script we get from blaze",
            String.format("EXE=%s", blazeCompilerExecutableFile.getPath()),
            "# Read in the arguments file so we can pass the arguments on the command line.",
            String.format("(cd %s && $EXE \"${parsedargs[@]}\")", executionRoot));

    try (PrintWriter pw = new PrintWriter(blazeCompilerWrapper, UTF_8.name())) {
      compilerWrapperScriptLines.forEach(pw::println);
    }
    return blazeCompilerWrapper;
  } catch (IOException e) {
    logger.warn(
        "Unable to write compiler wrapper script executable: " + blazeCompilerExecutableFile, e);
    return null;
  }
}
 
源代码18 项目: james-project   文件: MailsShouldBeWellReceived.java
@Test
default void mailsShouldBeWellReceivedByTenRecipient(GuiceJamesServer server) throws Exception {
    server.getProbe(DataProbeImpl.class).fluent()
            .addDomain(DOMAIN)
            .addUser(JAMES_USER, PASSWORD);

    ImmutableList<String> users = generateNUsers(10);

    users.forEach((ThrowingConsumer<String>) user -> server.getProbe(DataProbeImpl.class)
                    .fluent()
                    .addUser(user, PASSWORD));

    MailboxProbeImpl mailboxProbe = server.getProbe(MailboxProbeImpl.class);
    mailboxProbe.createMailbox("#private", JAMES_USER, DefaultMailboxes.INBOX);
    users.forEach((ThrowingConsumer<String>) user ->
                    mailboxProbe.createMailbox("#private", user, DefaultMailboxes.INBOX));


    Port smtpPort = server.getProbe(SmtpGuiceProbe.class).getSmtpPort();
    String message = Resources.toString(Resources.getResource("eml/htmlMail.eml"), StandardCharsets.UTF_8);

    try (SMTPMessageSender sender = new SMTPMessageSender(Domain.LOCALHOST.asString())) {
        sender.connect(JAMES_SERVER_HOST, smtpPort);
        sendUniqueMessageToUsers(sender, message, users);
    }

    CALMLY_AWAIT_FIVE_MINUTE.untilAsserted(() ->
        assertThat(
            server
                .getProbe(SpoolerProbe.class)
                .processingFinished()
        ).isTrue());

    try (TestIMAPClient reader = new TestIMAPClient()) {
        users.forEach((ThrowingConsumer<String>) user -> reader
            .connect(JAMES_SERVER_HOST, server.getProbe(ImapGuiceProbe.class).getImapPort())
            .login(user, PASSWORD)
            .select(TestIMAPClient.INBOX)
            .awaitMessageCount(CALMLY_AWAIT, 1));
    }
}
 
源代码19 项目: nomulus   文件: TransactionManagerTest.java
private static void assertAllEntitiesNotExist(ImmutableList<TestEntity> entities) {
  entities.forEach(TransactionManagerTest::assertEntityNotExist);
}
 
源代码20 项目: bazel   文件: NinjaGraphTest.java
@Test
public void testNinjaGraphRuleWithPhonyTree() throws Exception {
  rewriteWorkspace(
      "workspace(name = 'test')", "toplevel_output_directories(paths = ['build_config'])");

  // We do not have to have the real files in place, the rule only reads
  // the contents of Ninja files.
  scratch.file(
      "build_config/build.ninja",
      "rule cat",
      "  command = cat ${in} > ${out}",
      "rule echo",
      "  command = echo \"Hello $$(cat ${in} | tr '\\r\\n' ' ')!\" > ${out}",
      "build a: cat a.txt",
      "build b: cat b.txt",
      "build c: cat c.txt",
      "build d: cat d.txt",
      // e should be executed unconditionally as it depends on always-dirty phony action
      "build e: cat e.txt always_dirty",
      "build always_dirty: phony",
      "build group1: phony a b c",
      "build group2: phony d e",
      "build inputs_alias: phony group1 group2",
      "build hello.txt: echo inputs_alias",
      "build alias: phony hello.txt");

  ConfiguredTarget configuredTarget =
      scratchConfiguredTarget(
          "",
          "graph",
          "ninja_graph(name = 'graph', output_root = 'build_config',",
          " working_directory = 'build_config',",
          " main = 'build_config/build.ninja',",
          " output_root_inputs = ['a.txt', 'b.txt', 'c.txt', 'd.txt', 'e.txt'])");
  assertThat(configuredTarget).isInstanceOf(RuleConfiguredTarget.class);
  RuleConfiguredTarget ninjaConfiguredTarget = (RuleConfiguredTarget) configuredTarget;
  ImmutableList<ActionAnalysisMetadata> actions = ninjaConfiguredTarget.getActions();
  assertThat(actions).hasSize(5);
  List<String> outputs = Lists.newArrayList();
  actions.forEach(a -> outputs.add(Iterables.getOnlyElement(a.getOutputs()).getExecPathString()));
  assertThat(outputs)
      .containsExactlyElementsIn(
          new String[] {
            "build_config/a.txt",
            "build_config/b.txt",
            "build_config/c.txt",
            "build_config/d.txt",
            "build_config/e.txt"
          });

  for (ActionAnalysisMetadata action : actions) {
    assertThat(action).isInstanceOf(SymlinkAction.class);
    SymlinkAction symlinkAction = (SymlinkAction) action;
    assertThat(symlinkAction.executeUnconditionally()).isTrue();
    assertThat(symlinkAction.getInputPath().getParentDirectory())
        .isEqualTo(PathFragment.create("/workspace/build_config"));
    assertThat(symlinkAction.getInputPath().getFileExtension()).isEqualTo("txt");
    PathFragment execRootPath = symlinkAction.getPrimaryOutput().getExecPath();
    assertThat(execRootPath.getParentDirectory()).isEqualTo(PathFragment.create("build_config"));
    assertThat(execRootPath.getFileExtension()).isEqualTo("txt");
  }
}