|
|
@@ -7,6 +7,7 @@
|
|
|
package net.ranides.assira.io;
|
|
|
|
|
|
import net.ranides.assira.collection.query.CQuery;
|
|
|
+import net.ranides.assira.text.Wildcard;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
@@ -96,11 +97,11 @@ public final class PathUtils {
|
|
|
}
|
|
|
|
|
|
public static Path normalize(Path path) {
|
|
|
- return Paths.get(path.toAbsolutePath().toUri().normalize());
|
|
|
+ return path.toAbsolutePath().normalize();
|
|
|
}
|
|
|
|
|
|
public static String normalize(String path) {
|
|
|
- return Paths.get(Paths.get(path).toUri().normalize()).toString();
|
|
|
+ return normalize(Paths.get(path)).toString();
|
|
|
}
|
|
|
|
|
|
public static CQuery<Path> list(Path dir) {
|
|
|
@@ -111,6 +112,10 @@ public final class PathUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static CQuery<Path> list(Path dir, String wildcard) {
|
|
|
+ return PathUtils.list(dir).filter(Wildcard.compile(wildcard).asPathFilter());
|
|
|
+ }
|
|
|
+
|
|
|
public static CQuery<Path> walk(Path dir) {
|
|
|
try {
|
|
|
return CQuery.from().stream(() -> Files.walk(dir, FileVisitOption.FOLLOW_LINKS));
|
|
|
@@ -118,4 +123,38 @@ public final class PathUtils {
|
|
|
return CQuery.empty();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public static CQuery<Path> walk(Path dir, String wildcard) {
|
|
|
+ return PathUtils.walk(dir).filter(Wildcard.compile(wildcard).asPathFilter());
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Path cwd() {
|
|
|
+ return PathUtils.normalize(Paths.get("."));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Path common(Path a, Path b) {
|
|
|
+ return cwd().relativize(common0(a,b));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static Path common(Collection<Path> values) {
|
|
|
+ if(values.isEmpty()) {
|
|
|
+ return cwd();
|
|
|
+ }
|
|
|
+ return cwd().relativize(values.stream().reduce(values.iterator().next(), PathUtils::common0));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Path common0(Path a, Path b) {
|
|
|
+ Path na = PathUtils.normalize(a);
|
|
|
+ Path nb = PathUtils.normalize(b);
|
|
|
+
|
|
|
+ int i = 0;
|
|
|
+ int n = Math.min(na.getNameCount(), nb.getNameCount());
|
|
|
+
|
|
|
+ while(i<n && na.getName(i).equals(nb.getName(i))) {
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ return na.getRoot().resolve(na.subpath(0,i));
|
|
|
+ }
|
|
|
+
|
|
|
}
|