The easiest way to get rid of a Stream is to use an enhanced for loop. So when you see Stream.of on an array A, you can replace it with for (Type x : A). So start with
for (String file : arenaDirectory.list()) {
}
The operations on the Stream will then be what goes in the loop. The first is filter, which will eliminate elements of the stream and keep only those that meet a condition. That's equivalent to an if statement:
for (String file : arenaDirectory.list()) {
if (Stream.of(new File(arenaDirectory, file).list()).filter((childName) -> childName.equals(DATA_FILE_NAME)).count() > 0) {
}
}
Note that since I chose the same name for the loop variable as the original code used in the lambda, it's easy to just copy the predicate part of the lambda expression into the if.
Now you have map, which operates on the elements that the filter didn't eliminate and transforms them to something new. So you'll put the operation inside the if, and declare a variable to hold the new value:
for (String file : arenaDirectory.list()) {
if (Stream.of(new File(arenaDirectory, file).list()).filter((childName) -> childName.equals(DATA_FILE_NAME)).count() > 0) {
File arenaFolder = new File(arenaDirectory, file);
}
}
Again, I chose the same variable name that the code used in the next lambda.
The code then has forEach, which means to perform an operation on the new values returned by the map--which, in this case, is the arenaFolder variable created above. Here, I don't know what the code is, since your post had empty curly braces. But whatever it is, you will put it after the last statement; it will use arenaFolder for something:
for (String file : arenaDirectory.list()) {
if (Stream.of(new File(arenaDirectory, file).list()).filter((childName) -> childName.equals(DATA_FILE_NAME)).count() > 0) {
File arenaFolder = new File(arenaDirectory, file);
// code that does something with arenaFolder
}
}
Now all you have to do is follow the same steps to downport the nested stream. Instead of the count() operation, you'll have to keep your own counter--go through the loop and increment it whenever the "filter" condition is true. Or, since you're just using count to see if any condition matches, you don't really need a counter--just break as soon as you find a match.
arenaDirectoryis ajava.util.File?java.util.File?;java.io.File