// Path: mug/src/main/java/com/google/mu/util/stream/Cases.java
// static <T> Collector<T, ?, TinyContainer<T>> toTinyContainer() {
//   return Collector.of(TinyContainer::new, TinyContainer::add, TinyContainer::addAll);
// }


import java.util.stream.Collector;
import static com.google.mu.util.stream.Cases.TinyContainer.toTinyContainer;
import static java.util.Objects.requireNonNull;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.counting;
import static java.util.stream.Collectors.toList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
/*****************************************************************************
 * ------------------------------------------------------------------------- *
 * 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.mu.util.stream;



/**
 * Collectors for short streams with 0, 1 or 2 elements using a {@link Supplier}, {@link Function}
 * or {@link BiFunction} respectively.
 *
 * <p>For example, if the input collection must have only 2 elements:
 *
 * <pre>{@code
 * Foo result = input.stream().collect(onlyElements((a, b) -> ...));
 * }</pre>
 *
 * <p>Or, if the input may or may not have two elements:
 *
 * <pre>{@code
 * Optional<Foo> result = input.stream().collect(when((a, b) -> ...));
 * }</pre>
 *
 * <p>Or, if the input could have zero, one or two elements:
 *
 * <pre>{@code
 * Foo result = input.stream().collect(
 *     cases(
 *         when(() -> ...),
 *         when(a -> ...),
 *         when((a, b) -> ...)));
 * }</pre>
 *
 * @since 3.6
 * @deprecated Use {@link com.google.mu.util.MoreCollections#findFirstElements findFirstElements()}
 * and/or {@link com.google.mu.util.MoreCollections#findOnlyElements findOnlyElements()} methods
 * together with {@link Optional#or} instead.
 */
@Deprecated
public final class Cases {
  /**
   * A collector that collects the only element from the input,
   * or else throws {@link IllegalArgumentException}.
   */
  public static <T> Collector<T, ?, T> onlyElement() {
// Path: mug/src/main/java/com/google/mu/util/stream/Cases.java
// static <T> Collector<T, ?, TinyContainer<T>> toTinyContainer() {
//   return Collector.of(TinyContainer::new, TinyContainer::add, TinyContainer::addAll);
// }


// Path: mug/src/main/java/com/google/mu/util/stream/Cases.java
import java.util.stream.Collector;
import static com.google.mu.util.stream.Cases.TinyContainer.toTinyContainer;
import static java.util.Objects.requireNonNull;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.counting;
import static java.util.stream.Collectors.toList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

/*****************************************************************************
 * ------------------------------------------------------------------------- *
 * 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.mu.util.stream;



/**
 * Collectors for short streams with 0, 1 or 2 elements using a {@link Supplier}, {@link Function}
 * or {@link BiFunction} respectively.
 *
 * <p>For example, if the input collection must have only 2 elements:
 *
 * <pre>{@code
 * Foo result = input.stream().collect(onlyElements((a, b) -> ...));
 * }</pre>
 *
 * <p>Or, if the input may or may not have two elements:
 *
 * <pre>{@code
 * Optional<Foo> result = input.stream().collect(when((a, b) -> ...));
 * }</pre>
 *
 * <p>Or, if the input could have zero, one or two elements:
 *
 * <pre>{@code
 * Foo result = input.stream().collect(
 *     cases(
 *         when(() -> ...),
 *         when(a -> ...),
 *         when((a, b) -> ...)));
 * }</pre>
 *
 * @since 3.6
 * @deprecated Use {@link com.google.mu.util.MoreCollections#findFirstElements findFirstElements()}
 * and/or {@link com.google.mu.util.MoreCollections#findOnlyElements findOnlyElements()} methods
 * together with {@link Optional#or} instead.
 */
@Deprecated
public final class Cases {
  /**
   * A collector that collects the only element from the input,
   * or else throws {@link IllegalArgumentException}.
   */
  public static <T> Collector<T, ?, T> onlyElement() {
    return collectingAndThen(toTinyContainer(), TinyContainer::onlyOne);