added splitExtension function

This commit is contained in:
Walter Oggioni
2020-05-01 22:02:06 +01:00
committed by Walter Oggioni
parent d40a3e60c2
commit e50bbeb153

View File

@@ -2,6 +2,7 @@ package net.woggioni.jwo;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import net.woggioni.jwo.tuple.Tuple2;
import javax.net.ssl.*;
import java.io.*;
@@ -214,9 +215,9 @@ public class JWO {
*
* @param list the input list
* @param <T> the type parameter of the {@link List}
* @return the input list
* @throws IndexOutOfBoundsException if the list is empty
* @throws UnsupportedOperationException if the remove operation is not supported by this list
* @return the input list
*/
public static <T> T pop(List<T> list) {
return list.remove(list.size() - 1);
@@ -360,4 +361,15 @@ public class JWO {
.filter(Files::isExecutable)
.findFirst();
}
public static Optional<Tuple2<String, String>> splitExtension(Path file) {
String fileName = file.getFileName().toString();
int index = fileName.lastIndexOf('.');
if (index == -1) {
return Optional.empty();
} else {
return Optional.of(
new Tuple2<>(fileName.substring(0, index), fileName.substring(index)));
}
}
}