public static <ItemType> ItemType nth(
      final Collection<? extends ItemType> collection,
      final ICollectionFilter<ItemType> callback,
      final int index) {
    int counter = 0;

    for (final ItemType itemType : collection) {
      if (callback.qualifies(itemType)) {
        if (counter == index) {
          return itemType;
        }

        counter++;
      }
    }

    throw new IllegalStateException("Error: nth element does not exist");
  }
Performs an operation on all items that pass a filter check.

@param <ItemType> The type of the items in the collection.
@param <CollectionType> The type of the collection.
@param collection The collection that provides the items.
@param callback The callback that filters the collection and performs an operation on each item
    that passes the filter check.
java/zylib/src/main/java/com/google/security/zynamics/zylib/types/common/CollectionHelpers.java