//package com.liangjian.dataplatform.member.algorithm;
//
//import com.dangdang.ddframe.rdb.sharding.api.ShardingValue;
//import com.dangdang.ddframe.rdb.sharding.api.strategy.database.SingleKeyDatabaseShardingAlgorithm;
//
//import java.util.Collection;
//import java.util.LinkedHashSet;
//import java.util.List;
//import java.util.Map;
//import java.util.function.Function;
//import java.util.function.Predicate;
//
///**
// * @Author: 黄子奇
// * @Date: 2019/12/5
// */
//public class DatabaseShardingAlgorithm<K extends Comparable<?>> implements SingleKeyDatabaseShardingAlgorithm<K> {
//
//    private Integer tableCount;
//
//    public DatabaseShardingAlgorithm(Integer tableCount) {
//        this.tableCount = tableCount;
//    }
//
//    @Override
//    public String doEqualSharding(Collection<String> collection, ShardingValue<K> shardingValue) {
//        String suffix = Math.abs(shardingValue.getValue().hashCode()) % tableCount + "";
//        for (String tableName : collection) {
//            if(tableName.endsWith(suffix)) {
//                return tableName;
//            }
//        }
//        //没有匹配成功
//        throw new RuntimeException("分库算法未匹配");
//    }
//
//    @Override
//    public Collection<String> doInSharding(Collection<String> collection, ShardingValue<K> shardingValue) {
//        Collection<String> result = new LinkedHashSet<>(collection.size());
//        for (K value : shardingValue.getValues()) {
//            String suffix = Math.abs(value.hashCode()) % tableCount + "";
//            for (String tableName : collection) {
//                if(tableName.endsWith(suffix)) {
//                    result.add(tableName);
//                }
//            }
//        }
//        return result;
//    }
//
//    @Override
//    public Collection<String> doBetweenSharding(Collection<String> collection, ShardingValue<K> shardingValue) {
//        throw new RuntimeException("分库字段暂不支持Between");
//    }
//}
