@@ -66,6 +66,25 @@ public List<T> children() {
6666 return children ;
6767 }
6868
69+ @ SuppressWarnings ("unchecked" )
70+ public void forEachDown (Consumer <? super T > action ) {
71+ action .accept ((T ) this );
72+ // please do not refactor it to a for-each loop to avoid
73+ // allocating iterator that performs concurrent modification checks and extra stack frames
74+ for (int c = 0 , size = children .size (); c < size ; c ++) {
75+ children .get (c ).forEachDown (action );
76+ }
77+ }
78+
79+ /**
80+ * Same as forEachDown, but can end the traverse early, by setting the boolean argument in the action.
81+ */
82+ public boolean forEachDownMayReturnEarly (BiConsumer <? super T , Holder <Boolean >> action ) {
83+ var breakEarly = new Holder <>(false );
84+ forEachDownMayReturnEarly (action , breakEarly );
85+ return breakEarly .get ();
86+ }
87+
6988 @ SuppressWarnings ("unchecked" )
7089 void forEachDownMayReturnEarly (BiConsumer <? super T , Holder <Boolean >> action , Holder <Boolean > breakEarly ) {
7190 action .accept ((T ) this , breakEarly );
@@ -84,18 +103,6 @@ void forEachDownMayReturnEarly(BiConsumer<? super T, Holder<Boolean>> action, Ho
84103 }
85104 }
86105
87- public boolean forEachDownMayReturnEarly (BiConsumer <? super T , Holder <Boolean >> action ) {
88- var breakEarly = new Holder <>(false );
89- forEachDownMayReturnEarly (action , breakEarly );
90- return breakEarly .get ();
91- }
92-
93- public void forEachDown (Consumer <? super T > action ) {
94- boolean result = forEachDownMayReturnEarly ((p , breakFlag ) -> { action .accept (p ); });
95- // We should not be breaking early here...
96- assert result == false ;
97- }
98-
99106 @ SuppressWarnings ("unchecked" )
100107 public <E extends T > void forEachDown (Class <E > typeToken , Consumer <? super E > action ) {
101108 forEachDown (t -> {
0 commit comments