added splitExtension function
This commit is contained in:
@@ -2,6 +2,7 @@ package net.woggioni.jwo;
|
|||||||
|
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.woggioni.jwo.tuple.Tuple2;
|
||||||
|
|
||||||
import javax.net.ssl.*;
|
import javax.net.ssl.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@@ -214,9 +215,9 @@ public class JWO {
|
|||||||
*
|
*
|
||||||
* @param list the input list
|
* @param list the input list
|
||||||
* @param <T> the type parameter of the {@link List}
|
* @param <T> the type parameter of the {@link List}
|
||||||
|
* @return the input list
|
||||||
* @throws IndexOutOfBoundsException if the list is empty
|
* @throws IndexOutOfBoundsException if the list is empty
|
||||||
* @throws UnsupportedOperationException if the remove operation is not supported by this list
|
* @throws UnsupportedOperationException if the remove operation is not supported by this list
|
||||||
* @return the input list
|
|
||||||
*/
|
*/
|
||||||
public static <T> T pop(List<T> list) {
|
public static <T> T pop(List<T> list) {
|
||||||
return list.remove(list.size() - 1);
|
return list.remove(list.size() - 1);
|
||||||
@@ -333,7 +334,7 @@ public class JWO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T, U extends T> Optional<U> cast(T value, Class<U> cls) {
|
public static <T, U extends T> Optional<U> cast(T value, Class<U> cls) {
|
||||||
if(cls.isInstance(value)) {
|
if (cls.isInstance(value)) {
|
||||||
return Optional.of((U) value);
|
return Optional.of((U) value);
|
||||||
} else {
|
} else {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
@@ -360,4 +361,15 @@ public class JWO {
|
|||||||
.filter(Files::isExecutable)
|
.filter(Files::isExecutable)
|
||||||
.findFirst();
|
.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)));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user