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

com.wkit.lost.mybatis.lambda.LambdaConverter Maven / Gradle / Ivy

The newest version!
package com.wkit.lost.mybatis.lambda;

import com.wkit.lost.mybatis.utils.ArrayUtil;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Lambda转换器(对象转属性)
 * @param  Lambda对象
 * @author wvkity
 */
@FunctionalInterface
public interface LambdaConverter extends Serializable {
    
    /**
     * lambda对象转属性
     * @param lambda lambda对象
     * @return 字符串
     */
    String lambdaToProperty( R lambda );

    /**
     * lambda对象转属性
     * @param lambdas lambda对象数组
     * @return 属性集合
     */
    @SuppressWarnings( "unchecked" )
    default List lambdaToProperty( R... lambdas ) {
        List props;
        if ( !ArrayUtil.isEmpty( lambdas ) ) {
            props = Stream.of( lambdas )
                    .filter( Objects::nonNull )
                    .map( this::lambdaToProperty )
                    .collect( Collectors.toList() );
        } else {
            props = new ArrayList<>( 0 );
        }
        return props;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy