@Test public void testParseClients() { Map<String, Integer> clientsConfig = new HashMap<String, Integer>(); clientsConfig.put("1", new Integer("11")); clientsConfig.put("2", new Integer("21")); clientsConfig.put("3", new Integer("31")); clientsConfig.put("4", new Integer("41")); Map<Integer, Integer> clients = ShardingUtil.parseClients(clientsConfig); ApiLogger.debug("testParseClients clients:" + clients); Assert.assertEquals(new Integer("11"), clients.get(new Integer("1"))); Assert.assertEquals(new Integer("21"), clients.get(new Integer("2"))); Assert.assertEquals(new Integer("31"), clients.get(new Integer("3"))); Assert.assertEquals(new Integer("41"), clients.get(new Integer("4"))); }
public static<T> Map<Integer, T> parseClients(Map<String, T> clientsConfig){ Map<Integer, T> shardingClients = new HashMap<Integer, T>(); for(Map.Entry<String, T> entry : clientsConfig.entrySet()){ List<Integer> dbIdxs = parseDbIdx(entry.getKey()); T client = entry.getValue(); for(Integer dbIdx : dbIdxs){ shardingClients.put(dbIdx, client); } } return shardingClients; }
ShardingUtil { public static<T> Map<Integer, T> parseClients(Map<String, T> clientsConfig){ Map<Integer, T> shardingClients = new HashMap<Integer, T>(); for(Map.Entry<String, T> entry : clientsConfig.entrySet()){ List<Integer> dbIdxs = parseDbIdx(entry.getKey()); T client = entry.getValue(); for(Integer dbIdx : dbIdxs){ shardingClients.put(dbIdx, client); } } return shardingClients; } }
ShardingUtil { public static<T> Map<Integer, T> parseClients(Map<String, T> clientsConfig){ Map<Integer, T> shardingClients = new HashMap<Integer, T>(); for(Map.Entry<String, T> entry : clientsConfig.entrySet()){ List<Integer> dbIdxs = parseDbIdx(entry.getKey()); T client = entry.getValue(); for(Integer dbIdx : dbIdxs){ shardingClients.put(dbIdx, client); } } return shardingClients; }  }
ShardingUtil { public static<T> Map<Integer, T> parseClients(Map<String, T> clientsConfig){ Map<Integer, T> shardingClients = new HashMap<Integer, T>(); for(Map.Entry<String, T> entry : clientsConfig.entrySet()){ List<Integer> dbIdxs = parseDbIdx(entry.getKey()); T client = entry.getValue(); for(Integer dbIdx : dbIdxs){ shardingClients.put(dbIdx, client); } } return shardingClients; }  static Map<Integer, T> parseClients(Map<String, T> clientsConfig); }
ShardingUtil { public static<T> Map<Integer, T> parseClients(Map<String, T> clientsConfig){ Map<Integer, T> shardingClients = new HashMap<Integer, T>(); for(Map.Entry<String, T> entry : clientsConfig.entrySet()){ List<Integer> dbIdxs = parseDbIdx(entry.getKey()); T client = entry.getValue(); for(Integer dbIdx : dbIdxs){ shardingClients.put(dbIdx, client); } } return shardingClients; }  static Map<Integer, T> parseClients(Map<String, T> clientsConfig);  }