<commit_before>/*
 * Copyright (C) 2008 The Guava Authors
 *
 * 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.common.collect;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;

import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.SortedSet;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;

/**
 * An expanded {@code Iterable} API, providing functionality similar to Java 8's powerful <a href=
 * "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#package.description"
 * >streams library</a> in a slightly different way.
 *
 * <p>The following types of methods are provided:
 *
 * <ul>
 * <li>chaining methods which return a new {@code FluentIterable} based in some way on the contents
 *     of the current one (for example {@link #transform})
 * <li>element extraction methods which facilitate the retrieval of certain elements (for example
 *     {@link #last})
 * <li>query methods which answer questions about the {@code FluentIterable}'s contents (for example
 *     {@link #anyMatch})
 * <li>conversion methods which copy the {@code FluentIterable}'s contents into a new collection or
 *     array (for example {@link #toList})
 * </ul>
 *
 * <p>Several lesser-used features are currently available only as static methods on the {@link
 * Iterables} class.
 *
 * <a name="streams"></a>
 * <h3>Comparison to streams</h3>
 *
 * <p>Starting with Java 8, the core Java class libraries provide a new "Streams" library (in {@code
 * java.util.stream}), which is similar to {@code FluentIterable} but generally more powerful. Key
 * differences include:</b>
 *
 * <ul>
 * <li>A stream is <i>single-use</i>; it becomes invalid as soon as any "terminal operation" such as
 *     {@code findFirst()} or {@code iterator()} is invoked. (Even though {@code Stream} contains
 *     all the right method <i>signatures</i> to implement {@link Iterable}, it does not actually
 *     do so, to avoid implying repeat-iterability.) {@code FluentIterable}, on the other hand, is
 *     multiple-use, and does implement {@link Iterable}.
 * <li>Streams offer many features not found here, including {@code min/max}, {@code
 *     distinct}, {@code reduce}, {@code sorted}, the very powerful {@code collect}, and built-in
 *     support for parallelizing stream operations.
 * <li>{@code FluentIterable} contains several features not available on {@code Stream}, which are
 *     noted in the method descriptions below.
 * <li>Streams include primitive-specialized variants such as {@code IntStream}, the use of which is
 *     strongly recommended.
 * <li>Streams are standard Java, not requiring a third-party dependency (but do render your code
 *     incompatible with Java 7 and earlier).
 * </ul>
 *
 * <h3>Example</h3>
 *
 * <p>Here is an example that accepts a list from a database call, filters it based on a predicate,
 * transforms it by invoking {@code toString()} on each element, and returns the first 10 elements
 * as a {@code List}: <pre>   {@code
 *
 *   List<String> results =
 *       FluentIterable.from(database.getClientList())
 *           .filter(activeInLastMonthPredicate)
 *           .transform(Functions.toStringFunction())
 *           .limit(10)
 *           .toList();}</pre>
 *
 * The approximate stream equivalent is: <pre>   {@code
 *
 *   List<String> results =
 *       database.getClientList()
 *           .stream()
 *           .filter(activeInLastMonthPredicate)
 *           .map(Functions.toStringFunction())
 *           .limit(10)
 *           .collect(Collectors.toList());}</pre>
 *
 * @author <NAME>
 * @since 12.0
 */
@GwtCompatible(emulated = true)
public abstract class FluentIterable<E> implements Iterable<E> {
  // We store 'iterable' and use it instead of 'this' to allow Iterables to perform instanceof
  // checks on the _original_ iterable when FluentIterable.from is used.
  private final Iterable<E> iterable;

  /** Constructor for use by subclasses. */
  protected FluentIterable() {
    this.iterable = this;
  }

  FluentIterable(Iterable<E> iterable) {
    this.iterable = checkNotNull(iterable);
  }

  /**
   * Returns a fluent iterable that wraps {@code iterable}, or {@code iterable} itself if it
   * is already a {@code FluentIterable}.
   *
   * <p><b>{@code Stream} equivalent:</b> {@code iterable.stream()} if {@code iterable} is a
   * {@link Collection}; {@code StreamSupport.stream(iterable.spliterator(), false)} otherwise.
   */
  @CheckReturnValue
  public static <E> FluentIterable<E> from(final Iterable<E> iterable) {
    return (iterable instanceof FluentIterable)
        ? (FluentIterable<E>) iterable
        : new FluentIterable<E>(iterable) {
          @Override
          public Iterator<E> iterator() {
            return iterable.iterator();
          }
        };
  }

  /**
   * Returns a fluent iterable containing {@code elements} in the specified order.
   *
   * <p>The returned iterable is an unmodifiable view of the input array.
   *
   * <p><b>{@code Stream} equivalent:</b> {@code Stream.of(elements)} or {@code
   * Arrays.stream(elements)}.
   *
   * @since 20.0 (since 18.0 as an overload of {@code of})
   */
  @Beta
  @CheckReturnValue
  public static <E> FluentIterable<E> from(E[] elements) {
    return from(Arrays.asList(elements));
  }

  /**
   * Construct a fluent iterable from another fluent iterable. This is obviously never necessary,
   * but is intended to help call out cases where one migration from {@code Iterable} to
   * {@code FluentIterable} has obviated the need to explicitly convert to a {@code FluentIterable}.
   *
   * @deprecated instances of {@code FluentIterable} don't need to be converted to
   *     {@code FluentIterable}
   */
  @Deprecated
  @CheckReturnValue
  public static <E> FluentIterable<E> from(FluentIterable<E> iterable) {
    return checkNotNull(iterable);
  }

  /**
   * Returns a fluent iterable containing no elements.
   *
   * <p><b>{@code Stream} equivalent:</b> {@code Stream.empty()}.
   *
   * @since 20.0
   */
  @Beta
  @CheckReturnValue
  public static <E> FluentIterable<E> of() {
    return FluentIterable.from(ImmutableList.<E>of());
  }

  /**
   * Returns a fluent iterable containing {@code elements} in the specified order.
   *
   * <p>The returned iterable is modifiable, but modifications do not affect the input array.
   *
   * <p><b>{@code Stream} equivalent:</b> {@code Stream.of(elements)} or {@code
   * Arrays.stream(elements)}.
   *
   * @since 18.0
   */
  @Beta
  @CheckReturnValue
  // TODO(kak): @deprecated Use {@link #from(E[])} instead.
  public static <E> FluentIterable<E> of(E[] elements) {
    return from(Lists.newArrayList(elements));<commit_msg>Deprecate FluentIterable.of(E[]). ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=105753905<commit_after>/*
 * Copyright (C) 2008 The Guava Authors
 *
 * 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.common.collect;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;

import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.SortedSet;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;

/**
 * An expanded {@code Iterable} API, providing functionality similar to Java 8's powerful <a href=
 * "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#package.description"
 * >streams library</a> in a slightly different way.
 *
 * <p>The following types of methods are provided:
 *
 * <ul>
 * <li>chaining methods which return a new {@code FluentIterable} based in some way on the contents
 *     of the current one (for example {@link #transform})
 * <li>element extraction methods which facilitate the retrieval of certain elements (for example
 *     {@link #last})
 * <li>query methods which answer questions about the {@code FluentIterable}'s contents (for example
 *     {@link #anyMatch})
 * <li>conversion methods which copy the {@code FluentIterable}'s contents into a new collection or
 *     array (for example {@link #toList})
 * </ul>
 *
 * <p>Several lesser-used features are currently available only as static methods on the {@link
 * Iterables} class.
 *
 * <a name="streams"></a>
 * <h3>Comparison to streams</h3>
 *
 * <p>Starting with Java 8, the core Java class libraries provide a new "Streams" library (in {@code
 * java.util.stream}), which is similar to {@code FluentIterable} but generally more powerful. Key
 * differences include:</b>
 *
 * <ul>
 * <li>A stream is <i>single-use</i>; it becomes invalid as soon as any "terminal operation" such as
 *     {@code findFirst()} or {@code iterator()} is invoked. (Even though {@code Stream} contains
 *     all the right method <i>signatures</i> to implement {@link Iterable}, it does not actually
 *     do so, to avoid implying repeat-iterability.) {@code FluentIterable}, on the other hand, is
 *     multiple-use, and does implement {@link Iterable}.
 * <li>Streams offer many features not found here, including {@code min/max}, {@code
 *     distinct}, {@code reduce}, {@code sorted}, the very powerful {@code collect}, and built-in
 *     support for parallelizing stream operations.
 * <li>{@code FluentIterable} contains several features not available on {@code Stream}, which are
 *     noted in the method descriptions below.
 * <li>Streams include primitive-specialized variants such as {@code IntStream}, the use of which is
 *     strongly recommended.
 * <li>Streams are standard Java, not requiring a third-party dependency (but do render your code
 *     incompatible with Java 7 and earlier).
 * </ul>
 *
 * <h3>Example</h3>
 *
 * <p>Here is an example that accepts a list from a database call, filters it based on a predicate,
 * transforms it by invoking {@code toString()} on each element, and returns the first 10 elements
 * as a {@code List}: <pre>   {@code
 *
 *   List<String> results =
 *       FluentIterable.from(database.getClientList())
 *           .filter(activeInLastMonthPredicate)
 *           .transform(Functions.toStringFunction())
 *           .limit(10)
 *           .toList();}</pre>
 *
 * The approximate stream equivalent is: <pre>   {@code
 *
 *   List<String> results =
 *       database.getClientList()
 *           .stream()
 *           .filter(activeInLastMonthPredicate)
 *           .map(Functions.toStringFunction())
 *           .limit(10)
 *           .collect(Collectors.toList());}</pre>
 *
 * @author <NAME>
 * @since 12.0
 */
@GwtCompatible(emulated = true)
public abstract class FluentIterable<E> implements Iterable<E> {
  // We store 'iterable' and use it instead of 'this' to allow Iterables to perform instanceof
  // checks on the _original_ iterable when FluentIterable.from is used.
  private final Iterable<E> iterable;

  /** Constructor for use by subclasses. */
  protected FluentIterable() {
    this.iterable = this;
  }

  FluentIterable(Iterable<E> iterable) {
    this.iterable = checkNotNull(iterable);
  }

  /**
   * Returns a fluent iterable that wraps {@code iterable}, or {@code iterable} itself if it
   * is already a {@code FluentIterable}.
   *
   * <p><b>{@code Stream} equivalent:</b> {@code iterable.stream()} if {@code iterable} is a
   * {@link Collection}; {@code StreamSupport.stream(iterable.spliterator(), false)} otherwise.
   */
  @CheckReturnValue
  public static <E> FluentIterable<E> from(final Iterable<E> iterable) {
    return (iterable instanceof FluentIterable)
        ? (FluentIterable<E>) iterable
        : new FluentIterable<E>(iterable) {
          @Override
          public Iterator<E> iterator() {
            return iterable.iterator();
          }
        };
  }

  /**
   * Returns a fluent iterable containing {@code elements} in the specified order.
   *
   * <p>The returned iterable is an unmodifiable view of the input array.
   *
   * <p><b>{@code Stream} equivalent:</b> {@code Stream.of(elements)} or {@code
   * Arrays.stream(elements)}.
   *
   * @since 20.0 (since 18.0 as an overload of {@code of})
   */
  @Beta
  @CheckReturnValue
  public static <E> FluentIterable<E> from(E[] elements) {
    return from(Arrays.asList(elements));
  }

  /**
   * Construct a fluent iterable from another fluent iterable. This is obviously never necessary,
   * but is intended to help call out cases where one migration from {@code Iterable} to
   * {@code FluentIterable} has obviated the need to explicitly convert to a {@code FluentIterable}.
   *
   * @deprecated instances of {@code FluentIterable} don't need to be converted to
   *     {@code FluentIterable}
   */
  @Deprecated
  @CheckReturnValue
  public static <E> FluentIterable<E> from(FluentIterable<E> iterable) {
    return checkNotNull(iterable);
  }

  /**
   * Returns a fluent iterable containing no elements.
   *
   * <p><b>{@code Stream} equivalent:</b> {@code Stream.empty()}.
   *
   * @since 20.0
   */
  @Beta
  @CheckReturnValue
  public static <E> FluentIterable<E> of() {
    return FluentIterable.from(ImmutableList.<E>of());
  }

  /**
   * Returns a fluent iterable containing {@code elements} in the specified order.
   *
   * <p>The returned iterable is modifiable, but modifications do not affect the input array.
   *
   * <p><b>{@code Stream} equivalent:</b> {@code Stream.of(elements)} or {@code
   * Arrays.stream(elements)}.
   *
   * @deprecated Use {@link #from(E[])} instead (but note the differences in mutability). This
   *     method will be removed in Guava release 21.0.
   * @since 18.0
   */
  @Beta
  @CheckReturnValue
  @Deprecated
  public static <E> FluentIterable<E> of(E[] elements) {
    return from(Lists.newArrayList(elements));
{'fraction_non_alphanumeric': 0.11758248853877445, 'fraction_numerical': 0.0055530444889261964, 'mean_word_length': 3.6288105200239094, 'pattern_counts': {'":': 0, '<': 145, '<?xml version=': 0, '>': 145, 'https://': 3, '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': '3104631', 'n_tokens_mistral': 4556, 'n_tokens_neox': 4498, 'n_words': 1562}