NotificationStore { public Iterable<Notification> skip( final Iterable<Notification> notifications, final String startId, final boolean inclusive, final int limitSize) { Objects.requireNonNull(notifications, "notifications == null"); final int position = indexOf(notifications, startId); if (position == -1) { return Iterables.limit(notifications, limitSize); } if (inclusive) { return Iterables.limit(Iterables.skip(notifications, position), limitSize); } return Iterables.limit(Iterables.skip(notifications, position + 1), limitSize); } NotificationStore(
      final RiakClient client,
      final IdGenerator idGenerator,
      final CursorStore cursors,
      final RuleStore ruleStore,
      final Duration timeout,
      final Duration requestTimeout); void initialize(); Optional<UserNotifications> fetch(final String username); UserNotifications splitNotifications(
      final String username, @Nullable final SortedSet<Notification> notifications); Notification store(final String username, final Notification notification); void removeAll(final String username); void remove(final String username, final Collection<String> ids); static Stream<Notification> setUnseenState(
      final Iterable<Notification> notifications, final boolean unseen); static Optional<Notification> tryFind(
      final Iterable<Notification> notifications, final String id); static int indexOf(final Iterable<Notification> notifications, final String id); Iterable<Notification> skip(
      final Iterable<Notification> notifications,
      final String startId,
      final boolean inclusive,
      final int limitSize);  }
@Test public void testSkip() throws Exception { final ImmutableSortedSet.Builder<Notification> builder = ImmutableSortedSet.<Notification>naturalOrder(); for (int i = 1; i <= 100; i++) { builder.add(Notification.create(String.format("%03d", i))); } final ImmutableSortedSet<Notification> notifications = builder.build(); final ImmutableList.Builder<Notification> builder2 = ImmutableList.<Notification>builder(); for (int i = 100; i > 90; i--) { builder2.add(Notification.create(String.format("%03d", i))); } final List<Notification> expected = builder2.build(); final Iterable<Notification> actual = store.skip(notifications, "", true, 10); assertThat(actual).containsExactlyElementsOf(expected); }
@Test public void testSkipWithStart() throws Exception { final ImmutableSortedSet.Builder<Notification> builder = ImmutableSortedSet.<Notification>naturalOrder(); for (int i = 1; i <= 100; i++) { builder.add(Notification.create(String.format("%03d", i))); } final ImmutableSortedSet<Notification> notifications = builder.build(); final ImmutableList.Builder<Notification> builder2 = ImmutableList.<Notification>builder(); for (int i = 55; i > 45; i--) { builder2.add(Notification.create(String.format("%03d", i))); } final List<Notification> expected = builder2.build(); final Iterable<Notification> actual = store.skip(notifications, "056", false, 10); assertThat(actual).containsExactlyElementsOf(expected); }
@Test public void testSkipWithStartNotFound() throws Exception { final ImmutableSortedSet.Builder<Notification> builder = ImmutableSortedSet.<Notification>naturalOrder(); for (int i = 1; i <= 100; i++) { builder.add(Notification.create(String.format("%04d", i))); } final ImmutableSortedSet<Notification> notifications = builder.build(); final ImmutableList.Builder<Notification> builder2 = ImmutableList.<Notification>builder(); for (int i = 100; i > 90; i--) { builder2.add(Notification.create(String.format("%04d", i))); } final List<Notification> expected = builder2.build(); final Iterable<Notification> actual = store.skip(notifications, "1000", true, 10); assertThat(actual).containsExactlyElementsOf(expected); }