public static interface Stream.Builder
implements Consumer<T>
| java.util.stream.Stream.Builder<T> |
Stream可变建设者。 这允许创建的Stream通过单独发电元件,并将它们添加到Builder (而没有来自使用复制的开销ArrayList作为临时缓冲器)。
流生成器具有生命周期,该生命周期始于构建阶段,在此阶段中可以添加元素,然后过渡到构建阶段,之后可能不会添加元素。 构建阶段在调用build()方法时开始,该方法创建一个有序的Stream其元素是添加到流构建器的元素,按照它们添加的顺序。
也可以看看:
公共方法(Public methods) |
|
|---|---|
abstract void |
accept(T t) 为正在构建的流添加一个元素。 |
default Builder<T> |
add(T t) 为正在构建的流添加一个元素。 |
abstract Stream<T> |
build() 构建流,将此构建器转换为构建状态。 |
继承方法(Inherited methods) |
|
|---|---|
java.util.function.Consumer
|
|
void accept (T t)
为正在构建的流添加一个元素。
| 参数(Parameters) | |
|---|---|
t |
T: the input argument |
| 抛出异常(Throws) | |
|---|---|
IllegalStateException |
if the builder has already transitioned to the built state |
Builder<T> add (T t)
为正在构建的流添加一个元素。
accept(t)
return this;
| 参数(Parameters) | |
|---|---|
t |
T: the element to add |
| 返回(Returns) | |
|---|---|
Builder<T> |
this builder |
| 抛出异常(Throws) | |
|---|---|
IllegalStateException |
if the builder has already transitioned to the built state |
Stream<T> build ()
构建流,将此构建器转换为构建状态。 如果在构建器进入构建状态后还有其他尝试在构建器上进行操作,则会抛出IllegalStateException 。
| 返回(Returns) | |
|---|---|
Stream<T> |
the built stream |
| 抛出异常(Throws) | |
|---|---|
IllegalStateException |
if the builder has already transitioned to the built state |