@Test public void testEscapes() throws NoSuchAlgorithmException, SharderException { LilySharder lilySharder = new LilySharder(3); assertEquals(2, lilySharder.getShard("USER.apple\\.banana\\.pear")); assertEquals(0, lilySharder.getShard("USER.apple\\=banana\\=pear")); }
public int getShard(String id) throws SharderException { String[] parts = LilySharder.escapedSplit(id, '.'); if (parts.length < 2) { throw new RuntimeException("Does not look like a Lily id: " + id); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(escapeReservedCharacters(parts[0])); stringBuilder.append("."); stringBuilder.append(escapeReservedCharacters(parts[1])); long h = hash(stringBuilder.toString()); return (int) ((h % numShards) + numShards) % numShards; }
LilySharder implements Sharder { public int getShard(String id) throws SharderException { String[] parts = LilySharder.escapedSplit(id, '.'); if (parts.length < 2) { throw new RuntimeException("Does not look like a Lily id: " + id); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(escapeReservedCharacters(parts[0])); stringBuilder.append("."); stringBuilder.append(escapeReservedCharacters(parts[1])); long h = hash(stringBuilder.toString()); return (int) ((h % numShards) + numShards) % numShards; } }
LilySharder implements Sharder { public int getShard(String id) throws SharderException { String[] parts = LilySharder.escapedSplit(id, '.'); if (parts.length < 2) { throw new RuntimeException("Does not look like a Lily id: " + id); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(escapeReservedCharacters(parts[0])); stringBuilder.append("."); stringBuilder.append(escapeReservedCharacters(parts[1])); long h = hash(stringBuilder.toString()); return (int) ((h % numShards) + numShards) % numShards; } LilySharder(int numShards); }
LilySharder implements Sharder { public int getShard(String id) throws SharderException { String[] parts = LilySharder.escapedSplit(id, '.'); if (parts.length < 2) { throw new RuntimeException("Does not look like a Lily id: " + id); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(escapeReservedCharacters(parts[0])); stringBuilder.append("."); stringBuilder.append(escapeReservedCharacters(parts[1])); long h = hash(stringBuilder.toString()); return (int) ((h % numShards) + numShards) % numShards; } LilySharder(int numShards); int getShard(String id); }
LilySharder implements Sharder { public int getShard(String id) throws SharderException { String[] parts = LilySharder.escapedSplit(id, '.'); if (parts.length < 2) { throw new RuntimeException("Does not look like a Lily id: " + id); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(escapeReservedCharacters(parts[0])); stringBuilder.append("."); stringBuilder.append(escapeReservedCharacters(parts[1])); long h = hash(stringBuilder.toString()); return (int) ((h % numShards) + numShards) % numShards; } LilySharder(int numShards); int getShard(String id);  }