<commit_before>/*
 * Copyright (C) 2014 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.cloud.genomics.utils;

import java.io.IOException;
import java.util.Iterator;

import com.google.api.client.json.GenericJson;
import com.google.api.services.genomics.Genomics;
import com.google.api.services.genomics.GenomicsRequest;
import com.google.api.services.genomics.model.Callset;
import com.google.api.services.genomics.model.Job;
import com.google.api.services.genomics.model.Read;
import com.google.api.services.genomics.model.Readset;
import com.google.api.services.genomics.model.SearchCallsetsRequest;
import com.google.api.services.genomics.model.SearchCallsetsResponse;
import com.google.api.services.genomics.model.SearchJobsRequest;
import com.google.api.services.genomics.model.SearchJobsResponse;
import com.google.api.services.genomics.model.SearchReadsRequest;
import com.google.api.services.genomics.model.SearchReadsResponse;
import com.google.api.services.genomics.model.SearchReadsetsRequest;
import com.google.api.services.genomics.model.SearchReadsetsResponse;
import com.google.api.services.genomics.model.SearchVariantsRequest;
import com.google.api.services.genomics.model.SearchVariantsResponse;
import com.google.api.services.genomics.model.Variant;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.AbstractSequentialIterator;
import com.google.common.collect.FluentIterable;

/**
 * An abstraction that understands the {@code pageToken} / {@code nextPageToken} protocol for
 * paging results back to the user.
 *
 * The {@link #search(GenericJson, GenomicsRequestInitializer)} method can obtain an
 * {@link Iterable} to the objects returned from a search request. Although it is possible to
 * invoke this method directly, the {@code Iterable} that is returned may throw
 * {@link SearchException} during iteration. Client code is responsible for catching this exception
 * where the {@code Iterable} is consumed, unwrapping the underlying {@link IOException}, and
 * handling or rethrowing it.
 *
 * A safer alternative for consuming the results of a search is
 * {@link #search(GenericJson, GenomicsRequestInitializer, Callback)}. This method requires the
 * client code to pass in a {@link Callback} object that consumes the search results and will
 * unwrap and rethrow {@link IOException}s that occur during iteration for you.
 *
 * @param <A> The API type. One of {@link Genomics.Callsets}, {@link Genomics.Jobs},
 *            {@link Genomics.Reads}, {@link Genomics.Readsets}, or {@link Genomics.Variants}.
 * @param <B> The request type. One of {@link SearchCallsetsRequest}, {@link SearchJobsRequest},
 *            {@link SearchReadsRequest}, {@link SearchReadsetsRequest}, or
 *            {@link SearchVariantsRequest}.
 * @param <C> The {@link GenomicsRequest} type. One of {@link Genomics.Callsets.Search},
 *            {@link Genomics.Jobs.Search}, {@link Genomics.Reads.Search},
 *            {@link Genomics.Readsets.Search}, or {@link Genomics.Variants.Search}.
 * @param <D> The response type. One of {@link SearchCallsetsResponse}, {@link SearchJobsResponse},
 *            {@link SearchReadsResponse}, {@link SearchReadsetsResponse}, or
 *            {@link SearchVariantsResponse}.
 * @param <E> The type of object being streamed back to the user. One of {@link Callset},
 *            {@link Job}, {@link Read}, {@link Readset}, or {@link Variant}.
 */<commit_msg>Updated javadoc<commit_after>/*
 * Copyright (C) 2014 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.cloud.genomics.utils;

import java.io.IOException;
import java.util.Iterator;

import com.google.api.client.json.GenericJson;
import com.google.api.services.genomics.Genomics;
import com.google.api.services.genomics.GenomicsRequest;
import com.google.api.services.genomics.model.Callset;
import com.google.api.services.genomics.model.Dataset;
import com.google.api.services.genomics.model.Job;
import com.google.api.services.genomics.model.Read;
import com.google.api.services.genomics.model.Readset;
import com.google.api.services.genomics.model.SearchCallsetsRequest;
import com.google.api.services.genomics.model.SearchCallsetsResponse;
import com.google.api.services.genomics.model.SearchJobsRequest;
import com.google.api.services.genomics.model.SearchJobsResponse;
import com.google.api.services.genomics.model.SearchReadsRequest;
import com.google.api.services.genomics.model.SearchReadsResponse;
import com.google.api.services.genomics.model.SearchReadsetsRequest;
import com.google.api.services.genomics.model.SearchReadsetsResponse;
import com.google.api.services.genomics.model.SearchVariantsRequest;
import com.google.api.services.genomics.model.SearchVariantsResponse;
import com.google.api.services.genomics.model.Variant;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.AbstractSequentialIterator;
import com.google.common.collect.FluentIterable;

/**
 * An abstraction that understands the {@code pageToken} / {@code nextPageToken} protocol for paging
 * results back to the user.
 *
 * <p>The {@link #search(GenericJson, GenomicsRequestInitializer)} method can obtain an
 * {@link Iterable} to the objects returned from a search request. Although it is possible to invoke
 * this method directly, the {@code Iterable} that is returned may throw {@link SearchException}
 * during iteration. Client code is responsible for catching this exception where the
 * {@code Iterable} is consumed, unwrapping the underlying {@link IOException}, and handling or
 * rethrowing it.</p>
 *
 * <p>A safer alternative for consuming the results of a search is
 * {@link #search(GenericJson, GenomicsRequestInitializer, Callback)}. This method requires the
 * client code to pass in a {@link Callback} object that consumes the search results and will unwrap
 * and rethrow {@link IOException}s that occur during iteration for you.</p>
 *
 * <p>Example usage: Fetching all {@link Readset}s in a {@link Dataset}:</p>
 * <pre>
 * {@code
 * Genomics stub = ...;
 * String datasetId = ...;
 * Paginator.Readsets searchReadsets = Paginator.Readsets.create(stub);
 * for (Readset readset =
 *     searchReadsets.search(new SearchReadsetsRequest().setDatasetId(datasetId))) {
 *   // do something with readset
 * }
 * }
 * </pre>
 *
 * @param <A> The API type. One of {@link com.google.api.services.genomics.Genomics.Callsets},
 *        {@link com.google.api.services.genomics.Genomics.Jobs},
 *        {@link com.google.api.services.genomics.Genomics.Reads},
 *        {@link com.google.api.services.genomics.Genomics.Readsets}, or
 *        {@link com.google.api.services.genomics.Genomics.Variants}.
 * @param <B> The request type. One of {@link SearchCallsetsRequest}, {@link SearchJobsRequest},
 *        {@link SearchReadsRequest}, {@link SearchReadsetsRequest}, or
 *        {@link SearchVariantsRequest}.
 * @param <C> The {@link GenomicsRequest} type. One of
 *        {@link com.google.api.services.genomics.Genomics.Callsets.Search},
 *        {@link com.google.api.services.genomics.Genomics.Jobs.Search},
 *        {@link com.google.api.services.genomics.Genomics.Reads.Search},
 *        {@link com.google.api.services.genomics.Genomics.Readsets.Search}, or
 *        {@link com.google.api.services.genomics.Genomics.Variants.Search}.
 * @param <D> The response type. One of {@link SearchCallsetsResponse}, {@link SearchJobsResponse},
 *        {@link SearchReadsResponse}, {@link SearchReadsetsResponse}, or
 *        {@link SearchVariantsResponse}.
 * @param <E> The type of object being streamed back to the user. One of {@link Callset},
 *        {@link Job}, {@link Read}, {@link Readset}, or {@link Variant}.
 */
{'fraction_non_alphanumeric': 0.11176470588235295, 'fraction_numerical': 0.0017758046614872365, 'mean_word_length': 4.555487053020962, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5155716', 'n_tokens_mistral': 2616, 'n_tokens_neox': 2542, 'n_words': 756}