/*
 * Copyright 2015 Google Inc. All Rights Reserved.
 *
 * 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.android.agera;

import android.support.annotation.NonNull;
import com.google.android.agera.Common.StaticProducer;

import static com.google.android.agera.Preconditions.checkNotNull;

/**
 * Utility methods for obtaining {@link Supplier} instances.
 *
 * Supplier 的工具类
 * 可以获取 Supplier
 */
public final class Suppliers {

    /**
     * Returns a {@link Supplier} that always supplies the given {@code object} when its
     * {@link Supplier#get()} is called.
     *
     * 构造一个 StaticProducer 实例
     * StaticProducer 实现了 Supplier、Function、Merger
     */
    @NonNull
    public static <T> Supplier<T> staticSupplier(@NonNull final T object) {
        return new StaticProducer<>(object);
    }


    /**
     * Returns a {@link Supplier} that always supplies the value returned from the given
     * {@link Function} {@code function} when called with {@code from}.
     *
     * 构造一个 Function -> Supplier 转换器实例
     */
    @NonNull
    public static <T, F> Supplier<T> functionAsSupplier(
            @NonNull final Function<F, T> function, @NonNull final F from) {
        return new FunctionToSupplierConverter<>(function, from);
    }


    /**
     * FunctionToSupplierConverter 作为
     * Function -> Supplier 的 转换器
     * FunctionToSupplierConverter 实现了 Supplier 接口
     * 实现了 get() 方法，并且用 Function 的 apply(...) 方法，将原生类型目标类型数据
     * 作为 Supplier 提供的数据
     *
     * @param <T> Function 的原始类型
     * @param <F> Function 的目标类型，也是 Supplier 的目标类型
     */
    private static final class FunctionToSupplierConverter<T, F> implements Supplier<T> {
        // 转换方法
        @NonNull
        private final Function<F, T> function;
        // 原始数据
        @NonNull
        private final F from;


        private FunctionToSupplierConverter(@NonNull final Function<F, T> function,
                                            @NonNull final F from) {
            // Preconditions.checkNotNull(...) 方法检查数据
            this.function = checkNotNull(function);
            // Preconditions.checkNotNull(...) 方法检查数据
            this.from = checkNotNull(from);
        }


        @NonNull
        @Override
        public T get() {
            /*
             * 利用 Function 的 apply(...) 方法，将原生类型目标类型数据
             * 作为 Supplier 提供的数据
             */
            return function.apply(from);
        }
    }


    /**
     * 屏蔽默认的构造方法
     */
    private Suppliers() {}
}

@@ -1123,16 +1123,28 @@
 ducer %E5%AE%9E%E4%BE%8B
+ %E4%BD%9C%E4%B8%BA Supplier
 %0A     * 
@@ -1962,30 +1962,39 @@
 ..) %E6%96%B9%E6%B3%95%EF%BC%8C%E5%B0%86%E5%8E%9F%E7%94%9F%E7%B1%BB%E5%9E%8B
+%E8%BD%AC%E4%B8%BA
 %E7%9B%AE%E6%A0%87%E7%B1%BB%E5%9E%8B%E6%95%B0%E6%8D%AE
+%EF%BC%8C%E7%84%B6%E5%90%8E%E7%9B%AE%E6%A0%87%E6%95%B0%E6%8D%AE
 %0A     * %E4%BD%9C%E4%B8%BA S
@@ -2041,17 +2041,16 @@
 unction 
-%E7%9A%84
 %E5%8E%9F%E5%A7%8B%E7%B1%BB%E5%9E%8B%0A   
@@ -2073,17 +2073,16 @@
 unction 
-%E7%9A%84
 %E7%9B%AE%E6%A0%87%E7%B1%BB%E5%9E%8B%EF%BC%8C%E4%B9%9F%E6%98%AF 
@@ -2090,17 +2090,16 @@
 upplier 
-%E7%9A%84
 %E7%9B%AE%E6%A0%87%E7%B1%BB%E5%9E%8B%0A   
@@ -2719,79 +2719,12 @@
     
-@NonNull%0A        @Override%0A        public T get() %7B%0A            /*%0A    
+/**%0A
     
@@ -2767,19 +2767,24 @@
 %E5%8E%9F%E7%94%9F%E7%B1%BB%E5%9E%8B
+%E8%BD%AC%E4%B8%BA
 %E7%9B%AE%E6%A0%87%E7%B1%BB%E5%9E%8B%E6%95%B0%E6%8D%AE
-%0A    
+%EF%BC%8C%E7%84%B6%E5%90%8E%E7%9B%AE%E6%A0%87%E6%95%B0%E6%8D%AE%0A
     
@@ -2817,22 +2817,108 @@
         
-    */
+*%0A         * @return%0A         */%0A        @NonNull%0A        @Override%0A        public T get() %7B
 %0A       

update Suppliers comments in agera-1.0.0-rc2 module