@Test public void testFindNearestSuccessorForTimestampWithStartTimestampGreaterThanLastTimestampInChronology() { Set<Timestamp> timestamps = new LinkedHashSet<Timestamp>(); timestamps.add(Timestamp.fromMicros(1000L)); for (int i = 0; i < Random.getScaleCount(); i++) { long increment = 0; while (increment == 0) { increment = Math.abs(Random.getScaleCount()); } timestamps.add(Timestamp.fromMicros( Iterables.getLast(timestamps).getMicros() + increment)); } Timestamp startTimestamp = Timestamp .fromMicros(Iterables.getLast(timestamps).getMicros() + 1000L); Assert.assertEquals(timestamps.size(), Timestamps .findNearestSuccessorForTimestamp(timestamps, startTimestamp)); }
public static int findNearestSuccessorForTimestamp( Set<Timestamp> timestamps, Timestamp sought) { int start = 0; int end = timestamps.size() - 1; while (start <= end) { int mid = (start + end) / 2; Timestamp stored = Iterables.get(timestamps, mid); if(sought.getMicros() == stored.getMicros()) { return mid; } else if(sought.getMicros() > stored.getMicros()) { start = mid + 1; } else { end = mid - 1; } } return start; }
Timestamps { public static int findNearestSuccessorForTimestamp( Set<Timestamp> timestamps, Timestamp sought) { int start = 0; int end = timestamps.size() - 1; while (start <= end) { int mid = (start + end) / 2; Timestamp stored = Iterables.get(timestamps, mid); if(sought.getMicros() == stored.getMicros()) { return mid; } else if(sought.getMicros() > stored.getMicros()) { start = mid + 1; } else { end = mid - 1; } } return start; } }
Timestamps { public static int findNearestSuccessorForTimestamp( Set<Timestamp> timestamps, Timestamp sought) { int start = 0; int end = timestamps.size() - 1; while (start <= end) { int mid = (start + end) / 2; Timestamp stored = Iterables.get(timestamps, mid); if(sought.getMicros() == stored.getMicros()) { return mid; } else if(sought.getMicros() > stored.getMicros()) { start = mid + 1; } else { end = mid - 1; } } return start; }  }
Timestamps { public static int findNearestSuccessorForTimestamp( Set<Timestamp> timestamps, Timestamp sought) { int start = 0; int end = timestamps.size() - 1; while (start <= end) { int mid = (start + end) / 2; Timestamp stored = Iterables.get(timestamps, mid); if(sought.getMicros() == stored.getMicros()) { return mid; } else if(sought.getMicros() > stored.getMicros()) { start = mid + 1; } else { end = mid - 1; } } return start; }  static int findNearestSuccessorForTimestamp(
            Set<Timestamp> timestamps, Timestamp sought); static int findNearestSuccessorForTimestamp(Set<Long> timestamps,
            long sought); }
Timestamps { public static int findNearestSuccessorForTimestamp( Set<Timestamp> timestamps, Timestamp sought) { int start = 0; int end = timestamps.size() - 1; while (start <= end) { int mid = (start + end) / 2; Timestamp stored = Iterables.get(timestamps, mid); if(sought.getMicros() == stored.getMicros()) { return mid; } else if(sought.getMicros() > stored.getMicros()) { start = mid + 1; } else { end = mid - 1; } } return start; }  static int findNearestSuccessorForTimestamp(
            Set<Timestamp> timestamps, Timestamp sought); static int findNearestSuccessorForTimestamp(Set<Long> timestamps,
            long sought);  }