package com.liangjian.dataplatform.member.algorithm;

import com.google.common.collect.Range;
//import io.shardingsphere.api.algorithm.sharding.RangeShardingValue;
//import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
//import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @hor: 黄子奇
 * @Date: 2019/12/5
 */
//@Deprecated
//public class TableShardingAlgorithm<K extends Comparable<K>> implements PreciseShardingAlgorithm<K> {
//
//    public TableShardingAlgorithm() {
//    }
////    private Integer tableCount;
////
////    public TableShardingAlgorithm(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");
////    }
//    @Override
//    public String doSharding(Collection<String> collection, PreciseShardingValue<K> preciseShardingValue) {
//        for (String name : collection) {
//                String suffix = Math.abs(preciseShardingValue.getValue().hashCode()) % collection.size() + "";
//                if (name.endsWith(suffix)) {
//                    //log.info("return name:"+name);
//                    return name;
//                }
//            }
//            return null;
//    }
//}