ModShardLocator extends AbstractCommonShardLocator<CTX> { @Override public Set<String> locateForBetween(ConditionContext ctx) { long lowerValue = (long) getNumberValue(ctx.getValue()); long upperValue = (long) getNumberValue(ctx.getSecondValue()); Set<String> shards = new HashSet<>(); if(lowerValue > upperValue) { return shards; } if(upperValue - lowerValue >= (mod -1)) { return ctx.getAllShards(); } if(upperValue == lowerValue) { int shard = Integer.parseInt(mod(mod, ctx.getValue())); shards.add(String.valueOf(shard)); return applySuffix(shards); } int lowerShard = Integer.parseInt(mod(mod, ctx.getValue())); int upperShard = Integer.parseInt(mod(mod, ctx.getSecondValue())); if(lowerShard < upperShard) { while(lowerShard <= upperShard) { shards.add(String.valueOf(lowerShard++)); } } else { while(lowerShard < mod) { shards.add(String.valueOf(lowerShard++)); } int shard = 0; while(shard <= upperShard) { shards.add(String.valueOf(shard++)); } } return applySuffix(shards); } ModShardLocator(Integer mod);  ModShardLocator(Integer mod, String zeroPaddingFormat); Set<String> locateByValue(Object value); @Override Set<String> locateForEqual(ConditionContext ctx); @Override Set<String> locateForGreaterThan(CTX ctx); @Override Set<String> locateForLessThan(CTX ctx); @Override Set<String> locateForBetween(ConditionContext ctx);  }
@Test public void testLocateForBetween() { assertEquals(set(0, 1), test.locateForBetween((exp(M, 0, 1)))); assertEquals(all, test.locateForBetween((exp(M, 0, 2)))); assertEquals(all, test.locateForBetween((exp(M, 0, 3)))); assertEquals(all, test.locateForBetween((exp(M, 0, 4)))); assertEquals(set(1, 2), test.locateForBetween((exp(M, 1, 2)))); assertEquals(all, test.locateForBetween((exp(M, 1, 3)))); assertEquals(all, test.locateForBetween((exp(M, 1, 4)))); assertEquals(set(2, 0), test.locateForBetween((exp(M, 2, 3)))); assertEquals(all, test.locateForBetween((exp(M, 2, 4)))); assertEquals(all, test.locateForBetween((exp(M, 2, 5)))); }
@Test public void testLocateForBetweenSame() { assertEquals(set(1), test.locateForBetween((exp(M, 1, 1)))); }
@Test public void testLocateForBetweenIllegal() { assertEquals(set(), test.locateForBetween((exp(M, 2, 1)))); }