26 lines
861 B
Java
26 lines
861 B
Java
package cryptosky.me.helpers;
|
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.time.ZoneId;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.Map;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.function.Function;
|
|
import java.util.function.Predicate;
|
|
|
|
public class Utils {
|
|
|
|
// Utility Function to be able to get one of all types
|
|
public static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) {
|
|
Map<Object, Boolean> seen = new ConcurrentHashMap<>();
|
|
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
|
|
}
|
|
|
|
public static LocalDateTime format(String T) {
|
|
DateTimeFormatter F = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX")
|
|
.withZone(ZoneId.of("UTC"));
|
|
return LocalDateTime.parse(T, F);
|
|
}
|
|
}
|