@Test public void testExtrapolate() { int shard = 1; assertEquals("Invalid extrapolation - scenario 0", SlotKey.of(Granularity.MIN_5, 1, shard), SlotKey.of(Granularity.FULL, 1, shard).extrapolate(Granularity.MIN_5)); assertEquals("Invalid extrapolation - scenario 1", SlotKey.of(Granularity.MIN_5, 43, shard), SlotKey.of(Granularity.FULL, 43, shard).extrapolate(Granularity.MIN_5)); assertEquals("Invalid extrapolation - scenario 2", SlotKey.of(Granularity.MIN_5, 24, shard), SlotKey.of(Granularity.MIN_5, 24, shard).extrapolate(Granularity.MIN_5)); assertEquals("Invalid extrapolation - scenario 3", SlotKey.of(Granularity.MIN_20, 0, shard), SlotKey.of(Granularity.MIN_5, 0, shard).extrapolate(Granularity.MIN_20)); assertEquals("Invalid extrapolation - scenario 4", SlotKey.of(Granularity.MIN_20, 0, shard), SlotKey.of(Granularity.MIN_5, 3, shard).extrapolate(Granularity.MIN_20)); assertEquals("Invalid extrapolation - scenario 5", SlotKey.of(Granularity.MIN_20, 1, shard), SlotKey.of(Granularity.MIN_5, 4, shard).extrapolate(Granularity.MIN_20)); assertEquals("Invalid extrapolation - scenario 6", SlotKey.of(Granularity.MIN_20, 4032 / 4 - 1, shard), SlotKey.of(Granularity.MIN_5, 4031, shard).extrapolate(Granularity.MIN_20)); assertEquals("Invalid extrapolation - scenario 7", SlotKey.of(Granularity.MIN_60, 0, shard), SlotKey.of(Granularity.MIN_5, 3, shard).extrapolate(Granularity.MIN_60)); assertEquals("Invalid extrapolation - scenario 8", SlotKey.of(Granularity.MIN_60, 0, shard), SlotKey.of(Granularity.MIN_5, 3, shard).extrapolate(Granularity.MIN_60)); assertEquals("Invalid extrapolation - scenario 9", SlotKey.of(Granularity.MIN_60, 1, shard), SlotKey.of(Granularity.MIN_5, 12, shard).extrapolate(Granularity.MIN_60)); assertEquals("Invalid extrapolation - scenario 10", SlotKey.of(Granularity.MIN_60, 4032 / 12 - 1, shard), SlotKey.of(Granularity.MIN_5, 4031, shard).extrapolate(Granularity.MIN_60)); assertEquals("Invalid extrapolation - scenario 11", SlotKey.of(Granularity.MIN_1440, 0, shard), SlotKey.of(Granularity.MIN_5, 3, shard).extrapolate(Granularity.MIN_1440)); assertEquals("Invalid extrapolation - scenario 12", SlotKey.of(Granularity.MIN_1440, 0, shard), SlotKey.of(Granularity.MIN_5, 287, shard).extrapolate(Granularity.MIN_1440)); assertEquals("Invalid extrapolation - scenario 13", SlotKey.of(Granularity.MIN_1440, 1, shard), SlotKey.of(Granularity.MIN_5, 288, shard).extrapolate(Granularity.MIN_1440)); assertEquals("Invalid extrapolation - scenario 14", SlotKey.of(Granularity.MIN_60, 0, shard), SlotKey.of(Granularity.MIN_20, 1, shard).extrapolate(Granularity.MIN_60)); assertEquals("Invalid extrapolation - scenario 15", SlotKey.of(Granularity.MIN_60, 0, shard), SlotKey.of(Granularity.MIN_20, 2, shard).extrapolate(Granularity.MIN_60)); assertEquals("Invalid extrapolation - scenario 16", SlotKey.of(Granularity.MIN_60, 1, shard), SlotKey.of(Granularity.MIN_20, 3, shard).extrapolate(Granularity.MIN_60)); }
public SlotKey extrapolate(Granularity destGranularity) { if (destGranularity.equals(this.getGranularity())) { return this; } if (!destGranularity.isCoarser(getGranularity())) { throw new IllegalArgumentException("Destination granularity must be coarser than the current granularity"); } int factor = getGranularity().numSlots() / destGranularity.numSlots(); int parentSlot = getSlot() / factor; return SlotKey.of(destGranularity, parentSlot, getShard()); }
SlotKey { public SlotKey extrapolate(Granularity destGranularity) { if (destGranularity.equals(this.getGranularity())) { return this; } if (!destGranularity.isCoarser(getGranularity())) { throw new IllegalArgumentException("Destination granularity must be coarser than the current granularity"); } int factor = getGranularity().numSlots() / destGranularity.numSlots(); int parentSlot = getSlot() / factor; return SlotKey.of(destGranularity, parentSlot, getShard()); } }
SlotKey { public SlotKey extrapolate(Granularity destGranularity) { if (destGranularity.equals(this.getGranularity())) { return this; } if (!destGranularity.isCoarser(getGranularity())) { throw new IllegalArgumentException("Destination granularity must be coarser than the current granularity"); } int factor = getGranularity().numSlots() / destGranularity.numSlots(); int parentSlot = getSlot() / factor; return SlotKey.of(destGranularity, parentSlot, getShard()); } private  SlotKey(Granularity granularity, int slot, int shard); }
SlotKey { public SlotKey extrapolate(Granularity destGranularity) { if (destGranularity.equals(this.getGranularity())) { return this; } if (!destGranularity.isCoarser(getGranularity())) { throw new IllegalArgumentException("Destination granularity must be coarser than the current granularity"); } int factor = getGranularity().numSlots() / destGranularity.numSlots(); int parentSlot = getSlot() / factor; return SlotKey.of(destGranularity, parentSlot, getShard()); } private  SlotKey(Granularity granularity, int slot, int shard); int getShard(); int getSlot(); Granularity getGranularity(); static SlotKey of(Granularity granularity, int slot, int shard); static SlotKey parse(String string); Collection<SlotKey> getChildrenKeys(); Collection<SlotKey> getChildrenKeys(Granularity destGranularity); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); SlotKey extrapolate(Granularity destGranularity); }
SlotKey { public SlotKey extrapolate(Granularity destGranularity) { if (destGranularity.equals(this.getGranularity())) { return this; } if (!destGranularity.isCoarser(getGranularity())) { throw new IllegalArgumentException("Destination granularity must be coarser than the current granularity"); } int factor = getGranularity().numSlots() / destGranularity.numSlots(); int parentSlot = getSlot() / factor; return SlotKey.of(destGranularity, parentSlot, getShard()); } private  SlotKey(Granularity granularity, int slot, int shard); int getShard(); int getSlot(); Granularity getGranularity(); static SlotKey of(Granularity granularity, int slot, int shard); static SlotKey parse(String string); Collection<SlotKey> getChildrenKeys(); Collection<SlotKey> getChildrenKeys(Granularity destGranularity); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); SlotKey extrapolate(Granularity destGranularity);  }