by Arcsech · 8y ago · 0 comments
Java streams read data from spinning rust and then does the selection in RAM. LINQ can send the "where" to the RDBMS and the RDBMS can use an index/btree lookup to read just the data needed where java streams would read umpty megabytes.
I don't know whether the JINQ people plan to write a good query generator. But if I were the maintainer, my plan would definitely be to focus on the API first and only then work on optimal backend implementation(s).
List<ProductDisplayInfo> list = Arrays
.asList(products)
.stream()
.filter(p -> p.getCategory() == 2 || p.getCategory() == 5 && isProductUnderDiscount(p))
.map(p -> new ProductDisplayInfo(p))
.collect(Collectors.toList());
https://docs.oracle.com/javase/8/docs/api/java/util/stream/p...For fun, you can further reduce the size of the code above (and IMO, make it clearer), but using `Arrays.stream(product)` and a method reference for the `map`:
List<ProductDisplayInfo> list = Arrays
.stream(products)
.filter(p -> p.getCategory() == 2 || p.getCategory() == 5 && isProductUnderDiscount(p))
.map(ProductDisplayInfo::new)
.collect(Collectors.toList());