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

com.tukeof.common.util.collection.CollectionUnionUtil Maven / Gradle / Ivy

The newest version!
package com.tukeof.common.util.collection;

import com.tukeof.common.annotation.NotNull;
import com.tukeof.common.annotation.Nullable;
import com.tukeof.common.util.ReflectUtil;
import com.tukeof.common.util.bean.BeanStringUtil;

import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;

/**
 * Create by tuke on 2019-02-14
 */
public class CollectionUnionUtil {

    // keyRowGetter
    // ReflectUtil::getFirstFieldValue
    // keyColumnFormatter
    // (K key) -> Collections.singletonList(key.toString())
    // blockColumnFormatter
    // (T bean) -> BeanStringUtil.toStringList(bean, excludeAnnotations)
    public static  List> unionVertical(
            @Nullable Class[] excludeAnnotations,
            int blockWidth,
            @NotNull List[] blocks) {
        return unionVertical(
                ReflectUtil::getFirstFieldValue,
                excludeAnnotations,
                blockWidth,
                blocks);
    }

    // keyColumnFormatter
    // (K key) -> Collections.singletonList(key.toString())
    // blockColumnFormatter
    // (T bean) -> BeanStringUtil.toStringList(bean, excludeAnnotations)
    public static  List> unionVertical(
            @NotNull Function keyRowGetter,
            @Nullable Class[] excludeAnnotations,
            int blockWidth,
            @NotNull List[] blocks) {
        return unionVertical(
                keyRowGetter,
                (K key) -> Collections.singletonList(key.toString()),
                excludeAnnotations,
                blockWidth,
                blocks);
    }

    // ---- ---- ---- ----    ---- ---- ---- ----    ---- ---- ---- ----

    // blockColumnFormatter
    // (T bean) -> BeanStringUtil.toStringList(bean, excludeAnnotations)
    public static  List> unionVertical(
            @NotNull Function keyRowGetter,
            @NotNull Function> keyColumnFormatter,
            @Nullable Class[] excludeAnnotations,
            int blockWidth,
            @NotNull List[] blocks) {
        return BasicCollectionUnionUtil.unionVertical(
                keyRowGetter,
                keyColumnFormatter,
                (T bean) -> BeanStringUtil.toStringList(bean, excludeAnnotations),
                blockWidth,
                blocks);
    }

    // keyColumnFormatter
    // (K key) -> Collections.singletonList(key.toString())
    public static  List> unionVertical(
            @NotNull Function keyRowGetter,
            @NotNull Function> blockColumnFormatter,
            int blockWidth,
            @NotNull List[] blocks) {
        return BasicCollectionUnionUtil.unionVertical(
                keyRowGetter,
                (K key) -> Collections.singletonList(key.toString()),
                blockColumnFormatter,
                blockWidth,
                blocks);
    }

    // ---- ---- ---- ----    ---- ---- ---- ----    ---- ---- ---- ----

    // keyColumnFormatter
    // (K key) -> Collections.singletonList(key.toString())
    public static  List> unionVertical(
            @NotNull Function[] keyRowGetters,
            @NotNull Function> keyColumnFormatter,
            @NotNull Function>[] blockColumnFormatters,
            int[] blockWidths,
            @NotNull List[] blocks) {
        return BasicCollectionUnionUtil.unionVertical(
                keyRowGetters,
                (K key) -> Collections.singletonList(key.toString()),
                blockColumnFormatters,
                blockWidths,
                blocks);
    }

    // ==== ==== ==== ====    ==== ==== ==== ====    ==== ==== ==== ====

    // keyColumnFormatter
    // (K key) -> Collections.singletonList(key.toString())
    // blockColumnFormatter
    // (T bean) -> BeanStringUtil.toStringList(bean, excludeAnnotations)
    public static  List> unionVertical(
            @Nullable Class[] excludeAnnotations,
            @NotNull Set keys,
            @Nullable int blockWidth,
            @NotNull Map[] blocks) {
        return unionVertical(
                (K key) -> Collections.singletonList(key.toString()),
                excludeAnnotations,
                keys,
                blockWidth,
                blocks);
    }

    // ---- ---- ---- ----    ---- ---- ---- ----    ---- ---- ---- ----

    // blockColumnFormatter
    // (T bean) -> BeanStringUtil.toStringList(bean, excludeAnnotations)
    public static  List> unionVertical(
            @NotNull Function> keyColumnFormatter,
            @Nullable Class[] excludeAnnotations,
            @NotNull Set keys,
            @Nullable int blockWidth,
            @NotNull Map[] blocks) {
        return BasicCollectionUnionUtil.unionVertical(
                keyColumnFormatter,
                (T bean) -> BeanStringUtil.toStringList(bean, excludeAnnotations),
                keys,
                blockWidth,
                blocks);
    }

    // keyColumnFormatter
    // (K key) -> Collections.singletonList(key.toString())
    public static  List> unionVertical(
            @NotNull Function> blockColumnsFormatter,
            @NotNull Set keys,
            @Nullable int blockWidth,
            @NotNull Map[] blocks) {
        return BasicCollectionUnionUtil.unionVertical(
                (K key) -> Collections.singletonList(key.toString()),
                blockColumnsFormatter,
                keys,
                blockWidth,
                blocks);
    }

    // ---- ---- ---- ----    ---- ---- ---- ----    ---- ---- ---- ----

    // keyColumnFormatter
    // (K key) -> Collections.singletonList(key.toString())
    public static  List> unionVertical(
            @NotNull Function>[] blockColumnsFormatters,
            @NotNull Set keys,
            @Nullable int[] blockWidths,
            @NotNull Map[] blocks) {
        return BasicCollectionUnionUtil.unionVertical(
                (K key) -> Collections.singletonList(key.toString()),
                blockColumnsFormatters,
                keys,
                blockWidths,
                blocks);
    }

}