-
Notifications
You must be signed in to change notification settings - Fork 572
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added toMutableList collector to mark the need for a mutable list
It's useful in cases where we need to modify the resulting list, which is not possible with the immutable list returned by the Stream#toList method. We use this method to differentiate between cases where a mutable list is necessary and to prevent the IDE from suggesting the use of Stream#toList. Issue: #3197
- Loading branch information
Showing
2 changed files
with
28 additions
and
2 deletions.
There are no files selected for viewing
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
25 changes: 25 additions & 0 deletions
25
name.abuchen.portfolio/src/name/abuchen/portfolio/util/CollectorsUtil.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,25 @@ | ||
package name.abuchen.portfolio.util; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collector; | ||
import java.util.stream.Collectors; | ||
|
||
public class CollectorsUtil | ||
{ | ||
private CollectorsUtil() | ||
{ | ||
} | ||
|
||
/** | ||
* This method returns a collector that gathers the elements into a mutable | ||
* ArrayList. It's useful in cases where we need to modify the resulting | ||
* list, which is not possible with the immutable list returned by the | ||
* Stream#toList method. We use this method to differentiate between cases | ||
* where a mutable list is necessary and to prevent the IDE from suggesting | ||
* the use of Stream#toList. | ||
*/ | ||
public static <T> Collector<T, ?, List<T>> toMutableList() | ||
{ | ||
return Collectors.toList(); | ||
} | ||
} |