@Test public void throwsIfResidueEqualsOrExceedsModulus() { assertThatThrownBy(() -> getPartitionedTimestamps(SEVENTY_THREE_TO_EIGHTY_TWO, 2, 2)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Absolute value of residue 2 equals or exceeds modulus 2 - no solutions"); assertThatThrownBy(() -> getPartitionedTimestamps(SEVENTY_THREE_TO_EIGHTY_TWO, -3, 2)) .isInstanceOf(IllegalArgumentException.class) .hasMessageMatching("Absolute value of residue -3 equals or exceeds modulus 2 - no solutions"); }
public static PartitionedTimestamps getPartitionedTimestamps(TimestampRange range, int residue, int modulus) { checkModulusAndResidue(residue, modulus); long startTimestamp = getLowestTimestampMatchingModulus(range.getLowerBound(), residue, modulus); long endTimestamp = range.getUpperBound() % modulus == residue ? range.getUpperBound() : getLowestTimestampMatchingModulus(range.getUpperBound(), residue, modulus) - modulus; if (startTimestamp > endTimestamp) { return ImmutablePartitionedTimestamps.builder() .start(range.getLowerBound()) .interval(modulus) .count(0) .build(); } int count = (int) ((endTimestamp - startTimestamp) / modulus) + 1; return ImmutablePartitionedTimestamps.builder() .start(startTimestamp) .interval(modulus) .count(count) .build(); }
TimestampRanges { public static PartitionedTimestamps getPartitionedTimestamps(TimestampRange range, int residue, int modulus) { checkModulusAndResidue(residue, modulus); long startTimestamp = getLowestTimestampMatchingModulus(range.getLowerBound(), residue, modulus); long endTimestamp = range.getUpperBound() % modulus == residue ? range.getUpperBound() : getLowestTimestampMatchingModulus(range.getUpperBound(), residue, modulus) - modulus; if (startTimestamp > endTimestamp) { return ImmutablePartitionedTimestamps.builder() .start(range.getLowerBound()) .interval(modulus) .count(0) .build(); } int count = (int) ((endTimestamp - startTimestamp) / modulus) + 1; return ImmutablePartitionedTimestamps.builder() .start(startTimestamp) .interval(modulus) .count(count) .build(); } }
TimestampRanges { public static PartitionedTimestamps getPartitionedTimestamps(TimestampRange range, int residue, int modulus) { checkModulusAndResidue(residue, modulus); long startTimestamp = getLowestTimestampMatchingModulus(range.getLowerBound(), residue, modulus); long endTimestamp = range.getUpperBound() % modulus == residue ? range.getUpperBound() : getLowestTimestampMatchingModulus(range.getUpperBound(), residue, modulus) - modulus; if (startTimestamp > endTimestamp) { return ImmutablePartitionedTimestamps.builder() .start(range.getLowerBound()) .interval(modulus) .count(0) .build(); } int count = (int) ((endTimestamp - startTimestamp) / modulus) + 1; return ImmutablePartitionedTimestamps.builder() .start(startTimestamp) .interval(modulus) .count(count) .build(); } private  TimestampRanges(); }
TimestampRanges { public static PartitionedTimestamps getPartitionedTimestamps(TimestampRange range, int residue, int modulus) { checkModulusAndResidue(residue, modulus); long startTimestamp = getLowestTimestampMatchingModulus(range.getLowerBound(), residue, modulus); long endTimestamp = range.getUpperBound() % modulus == residue ? range.getUpperBound() : getLowestTimestampMatchingModulus(range.getUpperBound(), residue, modulus) - modulus; if (startTimestamp > endTimestamp) { return ImmutablePartitionedTimestamps.builder() .start(range.getLowerBound()) .interval(modulus) .count(0) .build(); } int count = (int) ((endTimestamp - startTimestamp) / modulus) + 1; return ImmutablePartitionedTimestamps.builder() .start(startTimestamp) .interval(modulus) .count(count) .build(); } private  TimestampRanges(); static PartitionedTimestamps getPartitionedTimestamps(TimestampRange range, int residue, int modulus); }
TimestampRanges { public static PartitionedTimestamps getPartitionedTimestamps(TimestampRange range, int residue, int modulus) { checkModulusAndResidue(residue, modulus); long startTimestamp = getLowestTimestampMatchingModulus(range.getLowerBound(), residue, modulus); long endTimestamp = range.getUpperBound() % modulus == residue ? range.getUpperBound() : getLowestTimestampMatchingModulus(range.getUpperBound(), residue, modulus) - modulus; if (startTimestamp > endTimestamp) { return ImmutablePartitionedTimestamps.builder() .start(range.getLowerBound()) .interval(modulus) .count(0) .build(); } int count = (int) ((endTimestamp - startTimestamp) / modulus) + 1; return ImmutablePartitionedTimestamps.builder() .start(startTimestamp) .interval(modulus) .count(count) .build(); } private  TimestampRanges(); static PartitionedTimestamps getPartitionedTimestamps(TimestampRange range, int residue, int modulus);  }