feat: added the ability to filter and group downloaded songs

This commit is contained in:
antonio 2023-08-11 16:23:53 +02:00
parent 06e2729aca
commit e87eda2757
8 changed files with 449 additions and 78 deletions

View file

@ -0,0 +1,17 @@
package com.cappielloantonio.tempo.util;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
public class Util {
public static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) {
try {
Map<Object, Boolean> uniqueMap = new ConcurrentHashMap<>();
return t -> uniqueMap.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
} catch (NullPointerException exception) {
return null;
}
}
}