| | |
| | | public class HashModTableSuffix implements TableSuffix { |
| | | |
| | | private String hash; |
| | | private static final int MOD = 100; |
| | | private Long tableSize = 64L; |
| | | private String tableSuffix="-000"; |
| | | |
| | | public HashModTableSuffix(String hash) { |
| | | public HashModTableSuffix(String hash,long tableSize, String tableSuffix) { |
| | | if (StringUtils.isEmpty(hash)) { |
| | | throw new IllegalArgumentException("hash should not be null or empty"); |
| | | } |
| | | this.hash = hash; |
| | | this.tableSize=tableSize; |
| | | this.tableSuffix=tableSuffix; |
| | | } |
| | | |
| | | @Override |
| | | public String getSuffix() { |
| | | return String.format("_%d", hash.hashCode() / MOD); |
| | | String format = "%0" + (tableSuffix.length() - 1) + "d"; |
| | | return "_"+String.format(format, Math.abs(hash.hashCode()) % tableSize); |
| | | } |
| | | } |