2020 you will not java8 new features? (Viii) current source code analysis and configuration summary

Recorded, and then repeat to others, you mastered.

After completing forgotten how to do? record it. Notes blog. Rote is of no use.

ReferencePipeline

/**
 * Abstract base class for an intermediate pipeline stage or pipeline source
 * stage implementing whose elements are of type {@code U}.
 */
//引用管道   
//ReferencePipeline  表示流的源阶段与中间阶段。
//ReferencePipeline.head表示流中的源阶段。
 abstract class ReferencePipeline<P_IN, P_OUT>
        extends AbstractPipeline<P_IN, P_OUT, Stream<P_OUT>>
        implements Stream<P_OUT>  {  
 }

AbstractPipeline

/**
 * Abstract base class for "pipeline" classes, which are the core
 * implementations of the Stream interface and its primitive specializations.
 * Manages construction and evaluation of stream pipelines.
 *  
 * <p>An {@code AbstractPipeline} represents an initial portion of a stream
 * pipeline, encapsulating a stream source and zero or more intermediate
 * operations.  The individual {@code AbstractPipeline} objects are often
 * referred to as <em>stages</em>, where each stage describes either the stream
 * source or an intermediate operation.
 流管道的初始的一部分。
 *
 * <p>A concrete intermediate stage is generally built from an
 * {@code AbstractPipeline}, a shape-specific pipeline class which extends it
 * (e.g., {@code IntPipeline}) which is also abstract, and an operation-specific
 * concrete class which extends that.  {@code AbstractPipeline} contains most of
 * the mechanics of evaluating the pipeline, and implements methods that will be
 * used by the operation; the shape-specific classes add helper methods for
 * dealing with collection of results into the appropriate shape-specific
 * containers.
 *避免自动拆箱和装箱操作。
 * <p>After chaining a new intermediate operation, or executing a terminal
 * operation, the stream is considered to be consumed, and no more intermediate
 * or terminal operations are permitted on this stream instance.
 * 当链接完一个新的中间操作或者执行了终止操作之后, 这个流被认为被消费了。不允许再被操作了。
 * @implNote
 * <p>For sequential streams, and parallel streams without
 * <a href="package-summary.html#StreamOps">stateful intermediate
 * operations</a>, parallel streams, pipeline evaluation is done in a single
 * pass that "jams" all the operations together.  For parallel streams with
 * stateful operations, execution is divided into segments, where each
 * stateful operations marks the end of a segment, and each segment is
 * evaluated separately and the result used as the input to the next
 * segment.  In all cases, the source data is not consumed until a terminal
 * operation begins.
  只有终止操作开始的时候,源数据才会被消费。
 * @param <E_IN>  type of input elements
 * @param <E_OUT> type of output elements
 * @param <S> type of the subclass implementing {@code BaseStream}
 * @since 1.8
 */
abstract class AbstractPipeline<E_IN, E_OUT, S extends BaseStream<E_OUT, S>>
        extends PipelineHelper<E_OUT> implements BaseStream<E_OUT, S> {
}

The relationship between inner classes, and lambda expressions.

Essentially inner classes and lambda not the same thing. Just to complete the same operation.

Syntactic sugar lambda is not anonymous inner classes, or that abbreviation. It is a new form.

public class LambdaTest {
    //内部类,和lambda表达式之间的关系。
    Runnable r1 = () -> System.out.println(this); // this表示当前类的对象

    //匿名内部类
    Runnable r2 = new Runnable() {  //
        @Override
        public void run() {
            System.out.println(this);
            // this 表示匿名内部类的对象
        }
    };


    public static void main(String[] args) {
        LambdaTest lambdaTest = new LambdaTest();

        Thread t1 = new Thread(lambdaTest.r1);
        t1.start();

        System.out.println("- - -- - ");

        Thread t2 = new Thread(lambdaTest.r2);
        t2.start();
        //输出结果。
        //com.sinosoft.lis.test.LambdaTest@62661526
        //com.sinosoft.lis.test.LambdaTest$1@59a30351
    }

}

Use the template method pattern.

Stream is inert, the operation is delayed. When the terminating operation, will perform the operation.

TerminalOp. Interface class to terminate the operation.

Termination of operation are only four types, findOp foreachOp matchOp reduceOp

PipelineHelper

stream intermediate operations and termination of operating system-level analysis and design analysis

Intermediate operation

BaseStream -》 AbStractpipeline -》ReferencePipeline -》 Head || StatelessOP || statefulOp

Intermediate pipe member variable current source configured topmost source many sources stateless operation stateful intermediate operation

Stream is inert, the operation is delayed. When the terminating operation, will perform the operation. Until no termination operation, in the middle of the integration operation (Sink).

Termination of operation

TerminalOp -》 FindOp || ForeachOp || MatchOp || reduceOp

Topmost

TerminalSink

Termination of drinkers.

Guess you like

Origin www.cnblogs.com/wobushitiegan/p/12174438.html