Conversation
sproshev
suggested changes
Nov 30, 2016
|
|
||
| // Вернуть поток из объектов класса 'clazz' | ||
| public static <R> Stream<R> filterIsInstance(Stream<?> s, Class<R> clazz) { | ||
| return s.filter(clazz::isInstance).map(o -> (R) o); |
| map1.compute(key, (k,v) -> (v == null) ? val : val + v); | ||
| }); | ||
| return map1; | ||
| }); |
There was a problem hiding this comment.
см Collectors.groupingBy и Collectors.summingInt
| @Test | ||
| public void findPrinterSingleAndEmpty(){ | ||
| HashMap<String, List<String>> authors = new HashMap<>(); | ||
| authors.put("Mike", Arrays.asList()); |
There was a problem hiding this comment.
все такие вызовы без аргументов должны быть заменены на Collections.emptyList, а с одним аргументом на Collections.singletonList. Они не выделяют дополнительной памяти (массива)
| } | ||
|
|
||
| private void writeToFile(File file1, String... lines) throws FileNotFoundException { | ||
| PrintStream ps = new PrintStream(file1); |
Owner
Author
|
@sproshev Поправил |
sproshev
approved these changes
Dec 17, 2016
| .max(Comparator.comparing(entry -> entry.getValue() | ||
| .stream() | ||
| .mapToInt(String::length) | ||
| .sum())).get().getKey(); |
There was a problem hiding this comment.
лучше map(...::getKey).orElse(null), так не будет исключения, если compositions.isEmpty
| return orders.stream() | ||
| .flatMap(map -> map.entrySet().stream()) | ||
| .collect(Collectors.groupingBy(Map.Entry::getKey, | ||
| Collectors.reducing(0, Map.Entry::getValue, Integer::sum))); |
There was a problem hiding this comment.
Collectors.summingInt(Map.Entry::getValue)
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.
No description provided.