feat: Add Espresso options#1563
Merged
mykola-mokhnach merged 5 commits intoappium:masterfrom Oct 29, 2021
Merged
Conversation
valfirst
reviewed
Oct 29, 2021
Comment on lines
+65
to
+67
| return options == null | ||
| ? Optional.empty() | ||
| : Optional.ofNullable((R) options.getOrDefault(name, null)); |
Collaborator
There was a problem hiding this comment.
Suggested change
| return options == null | |
| ? Optional.empty() | |
| : Optional.ofNullable((R) options.getOrDefault(name, null)); | |
| return Optional.ofNullable(options).map(opts -> (R) opts.getOrDefault(name, null)); |
| } | ||
|
|
||
| public Map<String, Object> toMap() { | ||
| return options == null ? Collections.emptyMap() : options; |
Collaborator
There was a problem hiding this comment.
Suggested change
| return options == null ? Collections.emptyMap() : options; | |
| return Optional.ofNullable(options).orElseGet(Collections::emptyMap); |
Comment on lines
+54
to
+58
| if (value instanceof Number) { | ||
| toolsVersions.addProperty(name, (Number) value); | ||
| } else { | ||
| toolsVersions.addProperty(name, String.valueOf(value)); | ||
| } |
Collaborator
There was a problem hiding this comment.
Suggested change
| if (value instanceof Number) { | |
| toolsVersions.addProperty(name, (Number) value); | |
| } else { | |
| toolsVersions.addProperty(name, String.valueOf(value)); | |
| } | |
| toolsVersions.addProperty(name, value instanceof Number ? (Number) value : String.valueOf(value)); |
Contributor
Author
There was a problem hiding this comment.
I tried. Java compiler does not like that
| } | ||
|
|
||
| public JsonObject toJson() { | ||
| return json == null ? new JsonObject() : json; |
Collaborator
There was a problem hiding this comment.
Suggested change
| return json == null ? new JsonObject() : json; | |
| return Optional.ofNullable(json).orElseGet(JsonObject::new); |
Contributor
Author
There was a problem hiding this comment.
the previous option was shorter, but changed anyway
Comment on lines
+265
to
+272
| public Optional<Map<String, Integer>> getEi() { | ||
| Optional<Map<String, Object>> value = getOptionValue("ei"); | ||
| return value.map((v) -> v.entrySet().stream() | ||
| .collect(Collectors.toMap( | ||
| Map.Entry::getKey, (entry) -> Integer.parseInt(String.valueOf(entry.getValue()))) | ||
| ) | ||
| ); | ||
| } |
Collaborator
There was a problem hiding this comment.
Suggested change
| public Optional<Map<String, Integer>> getEi() { | |
| Optional<Map<String, Object>> value = getOptionValue("ei"); | |
| return value.map((v) -> v.entrySet().stream() | |
| .collect(Collectors.toMap( | |
| Map.Entry::getKey, (entry) -> Integer.parseInt(String.valueOf(entry.getValue()))) | |
| ) | |
| ); | |
| } | |
| public Optional<Map<String, Integer>> getEi() { | |
| Optional<Map<String, Object>> value = getOptionValue("ei"); | |
| return value.map((v) -> convertMapValues(v, Integer::parseInt)); | |
| } | |
| private <T> Map<String, T> convertMapValues(Map<String, Object> map, Function<String, T> converter) { | |
| return map.entrySet().stream().collect( | |
| Collectors.toMap(Map.Entry::getKey, (entry) -> converter.apply(String.valueOf(entry.getValue())))); | |
| } |
and then convertMapValues can be reused in the methods converting to Long, Float
valfirst
approved these changes
Oct 29, 2021
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Change list
Added a separate Option class to represent Espresso driver caps and updated the related tests.
Types of changes