com.softicar.platform.common.container.file.tree.FileTreeIterable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.container.file.tree;
import com.softicar.platform.common.container.iterable.recurse.RecurseIterator;
import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
public class FileTreeIterable implements Iterable {
private final Collection roots;
public FileTreeIterable(File root) {
this(Collections.singleton(root));
}
public FileTreeIterable(Collection roots) {
this.roots = roots;
}
@Override
public Iterator iterator() {
return new RecurseIterator<>(roots, FileTreeIterable::recurse);
}
private static Iterable recurse(File file) {
return file.isDirectory()? Arrays.asList(file.listFiles()) : null;
}
}