Changes between Version 1 and Version 2 of Ticket #11390, comment 132


Ignore:
Timestamp:
2016-07-23T22:43:35+02:00 (5 years ago)
Author:
michael2402
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #11390, comment 132

    v1 v2  
    44
    55I prefer having a new utils class for all that stream stuff. The current `Utils` class is pretty long already.
     6
     7I'd also deprecate the find() methods. You should rewrite your code as:
     8{{{
     9#!java
     10Optional<?> item = list.stream().filter(...).findFirst();
     11if (!item.isPresent()) {
     12    // handle error.
     13}
     14}}}
     15
     16It gives programmers the ability to search whatever they prefer (`findFirst()`, `findAny()` or the reduce((a, b) -> throw new Exception()) hack to get exactly one element) and to do a nicer error handling using `orElseThrow`, `orElseGet` or other methods. It would remove a lot of != null checks. And since those methods depend on JOSM predicate, we need to deprecate them any way.