mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 09:53:33 +00:00
feat: added the ability to filter and group downloaded songs
This commit is contained in:
parent
06e2729aca
commit
e87eda2757
8 changed files with 449 additions and 78 deletions
17
app/src/main/java/com/cappielloantonio/tempo/util/Util.java
Normal file
17
app/src/main/java/com/cappielloantonio/tempo/util/Util.java
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue