mjsax commented on a change in pull request #9107: URL: https://github.com/apache/kafka/pull/9107#discussion_r564766389
########## File path: streams/src/main/java/org/apache/kafka/streams/kstream/Branched.java ########## @@ -0,0 +1,149 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.streams.kstream; + +import java.util.Objects; +import java.util.function.Consumer; +import java.util.function.Function; + +/** + * The {@code Branched} class is used to define the optional parameters when building branches with + * {@link BranchedKStream}. + * + * @param <K> type of record key + * @param <V> type of record value + */ +public class Branched<K, V> implements NamedOperation<Branched<K, V>> { + + protected final String name; + protected final Function<? super KStream<K, V>, ? extends KStream<K, V>> chainFunction; + protected final Consumer<? super KStream<K, V>> chainConsumer; + + protected Branched(final String name, + final Function<? super KStream<K, V>, ? extends KStream<K, V>> chainFunction, + final Consumer<? super KStream<K, V>> chainConsumer) { + this.name = name; + this.chainFunction = chainFunction; + this.chainConsumer = chainConsumer; + } + + /** + * Create an instance of {@code Branched} with provided branch name suffix. + * + * @param name the branch name suffix to be used. If {@code null}, a default branch name suffix will be generated + * (see {@link BranchedKStream} description for details) + * @param <K> key type + * @param <V> value type + * @return a new instance of {@code Branched} + */ + public static <K, V> Branched<K, V> as(final String name) { + return new Branched<>(name, null, null); + } + + /** + * Create an instance of {@code Branched} with provided chain function. + * + * @param chain A function that will be applied to the branch. If the provided function returns + * {@code null}, its result is ignored, otherwise it is added to the {@code Map} returned + * by {@link BranchedKStream#defaultBranch()} or {@link BranchedKStream#noDefaultBranch()} (see + * {@link BranchedKStream} description for details). + * @param <K> key type + * @param <V> value type + * @return a new instance of {@code Branched} + */ + public static <K, V> Branched<K, V> withFunction( + final Function<? super KStream<K, V>, ? extends KStream<K, V>> chain) { + Objects.requireNonNull(chain, "chain function should not be null"); Review comment: nit: `should not` -> `cannot` (or `can't` if you prefer) ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org