-
-
Notifications
You must be signed in to change notification settings - Fork 543
Use TreeMap in Response #1198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Isira-Seneviratne
wants to merge
5
commits into
TeamNewPipe:dev
from
Isira-Seneviratne:Response-TreeMap
Closed
Use TreeMap in Response #1198
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
96e54dd
Use TreeMap in Response
Isira-Seneviratne 1933e94
Reuse map if it is a SortedMap instead of creating a new one
Isira-Seneviratne f44eaa4
Use List.of()
Isira-Seneviratne 607c8fe
Add NonNull annotation
Isira-Seneviratne fa22a12
Fix typo in Exception message
TobiGr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -5,26 +5,33 @@ | |
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.SortedMap; | ||
| import java.util.TreeMap; | ||
|
|
||
| /** | ||
| * A Data class used to hold the results from requests made by the Downloader implementation. | ||
| */ | ||
| public class Response { | ||
| private final int responseCode; | ||
| private final String responseMessage; | ||
| private final Map<String, List<String>> responseHeaders; | ||
| private final SortedMap<String, List<String>> responseHeaders; | ||
| private final String responseBody; | ||
|
|
||
| private final String latestUrl; | ||
|
|
||
| public Response(final int responseCode, | ||
| final String responseMessage, | ||
| @Nullable final Map<String, List<String>> responseHeaders, | ||
| @Nonnull final Map<String, List<String>> responseHeaders, | ||
| @Nullable final String responseBody, | ||
| @Nullable final String latestUrl) { | ||
| this.responseCode = responseCode; | ||
| this.responseMessage = responseMessage; | ||
| this.responseHeaders = responseHeaders == null ? Collections.emptyMap() : responseHeaders; | ||
|
|
||
| if (responseHeaders instanceof SortedMap) { | ||
| this.responseHeaders = (SortedMap<String, List<String>>) responseHeaders; | ||
| } else { | ||
| this.responseHeaders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); | ||
| this.responseHeaders.putAll(responseHeaders); | ||
| } | ||
|
Comment on lines
+28
to
+33
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mmmh, this still means that all items are reprocessed when building a I would just build a new |
||
|
|
||
| this.responseBody = responseBody == null ? "" : responseBody; | ||
| this.latestUrl = latestUrl; | ||
|
|
@@ -71,13 +78,8 @@ public String latestUrl() { | |
| */ | ||
| @Nullable | ||
| public String getHeader(final String name) { | ||
| for (final Map.Entry<String, List<String>> headerEntry : responseHeaders.entrySet()) { | ||
| final String key = headerEntry.getKey(); | ||
| if (key != null && key.equalsIgnoreCase(name) && !headerEntry.getValue().isEmpty()) { | ||
| return headerEntry.getValue().get(0); | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| // Header lookup is case-insensitive | ||
| final var values = responseHeaders.getOrDefault(name, Collections.emptyList()); | ||
| return values.isEmpty() ? null : values.get(0); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this changed to be
@Nonnull? Isn't this a breaking change?