public static String generateNameFromStagePayload(ExecutableStagePayload stagePayload) {
    StringBuilder sb = new StringBuilder();
    RunnerApi.Components components = stagePayload.getComponents();
    final int transformsCount = stagePayload.getTransformsCount();
    sb.append("[").append(transformsCount).append("]");
    Collection<String> names = new ArrayList<>();
    for (int i = 0; i < transformsCount; i++) {
      String name = components.getTransformsOrThrow(stagePayload.getTransforms(i)).getUniqueName();
      // Java: Remove the 'ParMultiDo(Anonymous)' suffix which just makes the name longer
      name = name.replaceFirst("/ParMultiDo\\(Anonymous\\)$", "");
      names.add(name);
    }
    sb.append(generateNameFromTransformNames(names, true));
    return sb.toString();
  }
@Test
  /* Test for generating readable operator names during translation. */
  public void testOperatorNameGeneration() throws Exception {
    Pipeline p = Pipeline.create();
    p.apply(Impulse.create())
        // Anonymous ParDo
        .apply(
            ParDo.of(
                new DoFn<byte[], String>() {
                  @ProcessElement
                  public void processElement(
                      ProcessContext processContext, OutputReceiver<String> outputReceiver) {}
                }))
        // Name ParDo
        .apply(
            "MyName",
            ParDo.of(
                new DoFn<String, Integer>() {
                  @ProcessElement
                  public void processElement(
                      ProcessContext processContext, OutputReceiver<Integer> outputReceiver) {}
                }))
        .apply(
            // Avoid nested Anonymous ParDo
            "Composite/Nested/ParDo",
            ParDo.of(
                new DoFn<Integer, Integer>() {
                  @ProcessElement
                  public void processElement(
                      ProcessContext processContext, OutputReceiver<Integer> outputReceiver) {}
                }));

    ExecutableStage firstEnvStage =
        GreedyPipelineFuser.fuse(PipelineTranslation.toProto(p)).getFusedStages().stream()
            .findFirst()
            .get();
    RunnerApi.ExecutableStagePayload basePayload =
        RunnerApi.ExecutableStagePayload.parseFrom(
            firstEnvStage.toPTransform("foo").getSpec().getPayload());

    String executableStageName =
        ExecutableStageTranslation.generateNameFromStagePayload(basePayload);

    assertThat(executableStageName, is("[3]{ParDo(Anonymous), MyName, Composite}"));
  }