NotificationStore { public static Optional<Notification> tryFind( final Iterable<Notification> notifications, final String id) { Objects.requireNonNull(notifications, "notifications == null"); if (Strings.isNullOrEmpty(id)) { return Optional.empty(); } final com.google.common.base.Optional<Notification> result = Iterables.tryFind( notifications, notification -> { final Optional<String> notificationId = notification.getId(); if (!notificationId.isPresent()) { return false; } else if (id.equals(notificationId.get())) { return true; } final Collection<Notification> children = notification.getNotifications(); if (children.isEmpty()) { return false; } return (tryFind(children, id)).isPresent(); }); return result.toJavaUtil(); } 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 testFindNotification() throws Exception { final Notification n100 = Notification.builder() .withId("100") .withNotifications( Arrays.asList(Notification.create("101"), Notification.create("102"))) .build(); final Notification n150 = Notification.builder().withId("150").withNotifications(Collections.emptyList()).build(); final ImmutableList.Builder<Notification> builder = ImmutableList.builder(); for (int i = 1; i < 11; i++) { builder.add(Notification.create(String.format("%03d", i))); } builder.add(n100); builder.add(n150); builder.add(Notification.builder().build()); final List<Notification> notifications = builder.build(); assertThat(NotificationStore.tryFind(notifications, "001")) .isEqualTo(Optional.of(Notification.create("001"))); assertThat(NotificationStore.tryFind(notifications, "005")) .isEqualTo(Optional.of(Notification.create("005"))); assertThat(NotificationStore.tryFind(notifications, "010")) .isEqualTo(Optional.of(Notification.create("010"))); assertThat(NotificationStore.tryFind(notifications, "012")) .isEqualTo(Optional.<Notification>empty()); assertThat(NotificationStore.tryFind(notifications, "100")).isEqualTo(Optional.of(n100)); assertThat(NotificationStore.tryFind(notifications, "101")).isEqualTo(Optional.of(n100)); assertThat(NotificationStore.tryFind(notifications, "102")).isEqualTo(Optional.of(n100)); assertThat(NotificationStore.tryFind(notifications, "103")) .isEqualTo(Optional.<Notification>empty()); assertThat(NotificationStore.tryFind(notifications, "150")).isEqualTo(Optional.of(n150)); }