@@ -49,6 +49,8 @@ static Container of(Object... children) {
4949
5050 default <T > Stream <T > streamChildren (@ Nullable Class <? super T > type ) {
5151 return Stream .concat (getChildren ().stream (), streamOwnChildren ())
52+ .collect (Streams .expandRecursive (it -> Stream .of (it ).flatMap (Streams .cast (Container .class )).flatMap (c -> c .streamChildren (type ))))
53+ .distinct ()
5254 .flatMap (Streams .cast (type ))
5355 .sorted (Comparator .comparing (Object ::getClass , Order .COMPARATOR ))
5456 .map (Polyfill ::uncheckedCast );
@@ -67,18 +69,12 @@ default <T> Wrap<T> child(@Nullable Class<? super T> type) {
6769 }
6870
6971 private static Exception makeException (List <Throwable > errors ) {
70- return new Exception (String .format ("%d unexpected %s occurred" ,
71- errors .size (),
72- Polyfill .plural (errors , "exception" , "+s" )),
73- null ,
74- true , false ) {
75- };
72+ return new Exception (String .format ("%d unexpected %s occurred" , errors .size (), Polyfill .plural (errors , "exception" , "+s" )), null , true , false ) {};
7673 }
7774
7875 class Base implements Container , Reloadable {
79- @ Ignore @ Getter final Set <Object > children ;
80- @ Ignore @ Getter
81- private final AtomicReference <CompletableFuture <Void >> closed = new AtomicReference <>(new CompletableFuture <>());
76+ @ Ignore @ Getter final Set <Object > children ;
77+ @ Ignore @ Getter private final AtomicReference <CompletableFuture <Void >> closed = new AtomicReference <>(new CompletableFuture <>());
8278
8379 public Base (Object ... children ) {
8480 this .children = new HashSet <>(Set .of (children ));
@@ -96,17 +92,13 @@ public <T> Object addChild(@Nullable T it) {
9692
9793 @ Contract ("_ -> this" )
9894 public Object addChildren (@ Nullable Object @ NotNull ... children ) {
99- Stream .of (children )
100- .filter (Objects ::nonNull )
101- .forEach (this .children ::add );
95+ Stream .of (children ).filter (Objects ::nonNull ).forEach (this .children ::add );
10296 return this ;
10397 }
10498
10599 @ Override
106100 public int removeChildren (Object @ NotNull ... children ) {
107- return (int ) Stream .of (children )
108- .filter (this .children ::remove )
109- .count ();
101+ return (int ) Stream .of (children ).filter (this .children ::remove ).count ();
110102 }
111103
112104 @ Override
@@ -124,8 +116,7 @@ public void start() {
124116 @ SafeVarargs
125117 @ SneakyThrows
126118 protected final <T > void runOnChildren (Class <T > type , ThrowingConsumer <T , Throwable > task , Predicate <T > test , T ... extra ) {
127- final List <Throwable > errors = streamChildren (type )
128- .collect (append (moreMembers ().flatMap (cast (type ))))
119+ final List <Throwable > errors = streamChildren (type ).collect (append (moreMembers ().flatMap (cast (type ))))
129120 .collect (append (extra ))
130121 .filter (Objects ::nonNull )
131122 .filter (Predicate .not (this ::equals ))
@@ -142,24 +133,20 @@ protected final <T> void runOnChildren(Class<T> type, ThrowingConsumer<T, Throwa
142133 })
143134 .distinct ()
144135 .toList ();
145- if (errors .isEmpty ())
146- return ;
147- if (errors .size () == 1 )
148- throw errors .get (0 );
149- throw errors .stream ().collect (
150- () -> Container .makeException (errors ),
151- Throwable ::addSuppressed ,
152- (l , r ) -> Arrays .stream (r .getSuppressed ()).forEachOrdered (l ::addSuppressed ));
136+ if (errors .isEmpty ()) return ;
137+ if (errors .size () == 1 ) throw errors .get (0 );
138+ throw errors .stream ()
139+ .collect (() -> Container .makeException (errors ),
140+ Throwable ::addSuppressed ,
141+ (l , r ) -> Arrays .stream (r .getSuppressed ()).forEachOrdered (l ::addSuppressed ));
153142 }
154143
155144 protected Stream <AutoCloseable > moreMembers () {
156145 return Stream .empty ();
157146 }
158147
159148 public boolean setClosed (boolean state ) {
160- return Polyfill .updateBoolState (isClosed (), state ,
161- () -> closed .get ().complete (null ),
162- () -> closed .set (new CompletableFuture <>()));
149+ return Polyfill .updateBoolState (isClosed (), state , () -> closed .get ().complete (null ), () -> closed .set (new CompletableFuture <>()));
163150 }
164151
165152 @ Override
0 commit comments