-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
30 additions
and
52 deletions.
There are no files selected for viewing
52 changes: 0 additions & 52 deletions
52
src/main/java/io/github/yvasyliev/deezer/json/PagingMethodDeserializer.java
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
src/main/java/io/github/yvasyliev/deezer/json/deserializers/PagingMethodDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.github.yvasyliev.deezer.json.deserializers; | ||
|
||
import io.github.yvasyliev.deezer.json.exceptions.PagingMethodDeserializeException; | ||
import io.github.yvasyliev.deezer.methods.PagingMethod; | ||
import io.github.yvasyliev.deezer.objects.Page; | ||
import io.github.yvasyliev.deezer.objects.Pageable; | ||
import lombok.AllArgsConstructor; | ||
|
||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
@AllArgsConstructor | ||
public class PagingMethodDeserializer<T extends Pageable> extends AbstractPagingMethodDeserializer<T, PagingMethod<T>, Page<T>> { | ||
private final Map<Pattern, Function<Long, ? extends PagingMethod<? extends Pageable>>> pagingMethodFactories; | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
protected PagingMethod<T> createPagingMethod(String path, Map<String, String> queryParams) { | ||
for (Map.Entry<Pattern, Function<Long, ? extends PagingMethod<? extends Pageable>>> pagingMethodFactory : pagingMethodFactories.entrySet()) { | ||
Matcher matcher = pagingMethodFactory.getKey().matcher(path); | ||
if (matcher.matches()) { | ||
Long objectId = matcher.groupCount() > 0 ? Long.parseLong(matcher.group(1)) : null; | ||
return (PagingMethod<T>) pagingMethodFactory.getValue().apply(objectId); | ||
} | ||
} | ||
throw new PagingMethodDeserializeException(path, queryParams); | ||
} | ||
} |