// Path: core/src/main/java/com/github/phantomthief/util/MoreSuppliers.java
// public static <T> CloseableSupplier<T> lazy(Supplier<T> delegate) {
//     return lazy(delegate, true);
// }


import static com.github.phantomthief.util.MoreSuppliers.lazy;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.stream.Collectors.toMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.CancellationException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
package com.github.phantomthief.concurrent;




/**
 * @author w.vela
 * Created on 2018-06-25.
 */
class TryWaitResult<K, V> {

    private final Map<Future<? extends V>, V> success;
    private final Map<Future<? extends V>, Throwable> failed;
    private final Map<Future<? extends V>, TimeoutException> timeout;
    private final Map<Future<? extends V>, CancellationException> cancel;
    private final Map<Future<? extends V>, K> futureMap;

    private final Supplier<Map<K, V>> successMap;
    private final Supplier<Map<K, Throwable>> failedMap;
    private final Supplier<Map<K, TimeoutException>> timeoutMap;
    private final Supplier<Map<K, CancellationException>> cancelMap;

    TryWaitResult(Map<Future<? extends V>, V> success, Map<Future<? extends V>, Throwable> failed,
            Map<Future<? extends V>, TimeoutException> timeout,
            Map<Future<? extends V>, CancellationException> cancel,
            Map<Future<? extends V>, K> futureMap) {
        this.success = success;
        this.failed = failed;
        this.timeout = timeout;
        this.cancel = cancel;
        this.futureMap = futureMap;
        successMap = lazy(() -> transfer(this.success, this.futureMap));
        failedMap = lazy(() -> transfer(this.failed, this.futureMap));
        timeoutMap = lazy(() -> transfer(this.timeout, this.futureMap));
// Path: core/src/main/java/com/github/phantomthief/util/MoreSuppliers.java
// public static <T> CloseableSupplier<T> lazy(Supplier<T> delegate) {
//     return lazy(delegate, true);
// }


// Path: core/src/main/java/com/github/phantomthief/concurrent/TryWaitResult.java
import static com.github.phantomthief.util.MoreSuppliers.lazy;
import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.stream.Collectors.toMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.CancellationException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nonnull;

package com.github.phantomthief.concurrent;




/**
 * @author w.vela
 * Created on 2018-06-25.
 */
class TryWaitResult<K, V> {

    private final Map<Future<? extends V>, V> success;
    private final Map<Future<? extends V>, Throwable> failed;
    private final Map<Future<? extends V>, TimeoutException> timeout;
    private final Map<Future<? extends V>, CancellationException> cancel;
    private final Map<Future<? extends V>, K> futureMap;

    private final Supplier<Map<K, V>> successMap;
    private final Supplier<Map<K, Throwable>> failedMap;
    private final Supplier<Map<K, TimeoutException>> timeoutMap;
    private final Supplier<Map<K, CancellationException>> cancelMap;

    TryWaitResult(Map<Future<? extends V>, V> success, Map<Future<? extends V>, Throwable> failed,
            Map<Future<? extends V>, TimeoutException> timeout,
            Map<Future<? extends V>, CancellationException> cancel,
            Map<Future<? extends V>, K> futureMap) {
        this.success = success;
        this.failed = failed;
        this.timeout = timeout;
        this.cancel = cancel;
        this.futureMap = futureMap;
        successMap = lazy(() -> transfer(this.success, this.futureMap));
        failedMap = lazy(() -> transfer(this.failed, this.futureMap));
        timeoutMap = lazy(() -> transfer(this.timeout, this.futureMap));
        cancelMap = lazy(() -> transfer(this.cancel, this.futureMap));