IdGeneratorService { public int getShard(long id) { int mask = ((1 << shardIdBits) - 1) << shardIdShift; return (int) ((id & mask) >> shardIdShift); }  synchronized long generate(int shardId); int getShard(long id); long getTimestamp(long id); HashCode getHash(long id);  }
@Test public void getShard() { IdGeneratorService idGeneratorService = new IdGeneratorService(); for (int i = 0; i < 1024; i++) { long id = idGeneratorService.generate(i); assertEquals(idGeneratorService.getShard(id), i); } }