All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tech.ytsaurus.client.rows.ConsumerSource Maven / Gradle / Ivy

The newest version!
package tech.ytsaurus.client.rows;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.IntFunction;

@FunctionalInterface
public interface ConsumerSource extends Consumer {

    default void setRowCount(int rowCount) {
        // do nothing
    }

    static  ConsumerSource wrap(Consumer consumer) {
        return consumer::accept;
    }


    static  ConsumerSourceRet list() {
        return list(ArrayList::new);
    }


    static  ConsumerSourceRet list(IntFunction> function) {
        return new ConsumerSourceRet() {

            private List list;

            @Override
            public void setRowCount(int rowCount) {
                list = function.apply(rowCount);
            }

            @Override
            public void accept(T t) {
                if (list == null) {
                    list = new ArrayList<>();
                }
                list.add(t);
            }

            @Override
            public List get() {
                return list != null ? list : Collections.emptyList();
            }
        };
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy