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

cn.woodwhales.common.business.chinese.ChineseDataContainer Maven / Gradle / Ivy

There is a newer version: 3.8.3
Show newest version
package cn.woodwhales.common.business.chinese;

import cn.woodwhales.common.business.DataTool;
import com.google.common.base.Preconditions;
import com.google.common.collect.ComparisonChain;

import java.util.List;
import java.util.function.Function;

/**
 * 数据存储对象
 * @author woodwhales
 * 2020-12-07 22:27
 */
public class ChineseDataContainer {

    /**
     * 原始数据对象
     */
    private T data;

    /**
     * 要排序的对象属性名称
     */
    private String field;

    public ChineseDataContainer(T data, Function stringFunction) {
        Preconditions.checkNotNull(data);
        Preconditions.checkNotNull(stringFunction);
        this.data = data;
        this.field = stringFunction.apply(data);
    }

    public static  List> build(List dataList, Function stringFunction) {
        return DataTool.toList(dataList, data -> new ChineseDataContainer(data, stringFunction));
    }

    /**
     * 对中文字段进行比较
     * @param chineseDataContainer 中文数据容器
     * @return 比较结果值
     */
    public int compare(ChineseDataContainer chineseDataContainer) {
        return ComparisonChain.start()
                .compare(this.field, chineseDataContainer.getField(), ChineseDataTool.collator)
                .result();
    }

    public T getData() {
        return data;
    }

    public String getField() {
        return field;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy