@@ -177,22 +177,22 @@ protected Set<String> getDataEntityIds(RootDataEntity root, JsonNode graph) {
177
177
if (root == null ) { return Set .of (); }
178
178
Map <String , Set <String >> network = makeEntityGraph (graph );
179
179
Set <String > directDataEntities = new HashSet <>(root .hasPart );
180
- return Stream .concat (
181
- directDataEntities .stream (),
182
- directDataEntities .stream ().flatMap (entity -> getDataEntityIdsRecursive (entity , network ))
183
- ).collect (Collectors .toSet ());
184
- }
185
180
186
- protected Stream <String > getDataEntityIdsRecursive (
187
- String parent ,
188
- Map <String , Set <String >> network
189
- ) {
190
- return Stream .concat (
191
- Stream .of (parent ),
192
- network .getOrDefault (parent , new HashSet <>()).stream ()
193
- .flatMap (s -> getDataEntityIdsRecursive (s , network ))
194
- .filter (Objects ::nonNull )
195
- );
181
+ Stack <String > processingQueue = new Stack <>();
182
+ processingQueue .addAll (directDataEntities );
183
+ Set <String > result = new HashSet <>();
184
+
185
+ while (!processingQueue .empty ()) {
186
+ String currentId = processingQueue .pop ();
187
+ result .add (currentId );
188
+ network .getOrDefault (currentId , new HashSet <>()).stream ()
189
+ .filter (subId -> !result .contains (subId )) // avoid loops!
190
+ .forEach (subId -> {
191
+ result .add (subId );
192
+ processingQueue .add (subId );
193
+ });
194
+ }
195
+ return result ;
196
196
}
197
197
198
198
protected String unpackId (JsonNode node ) {
0 commit comments