Inner loop replaced by lambda.
Replaced by lambda (and by simpler algorithm - don't need going over squares, only values are interesting)
Replaced code by summarizing over lambda (first done totally manually without IDEA assistance)
Recommended way to work with Stream API - is moving to Stream whenever possible.
Thus don't need conversion from old to new API at all.
This is the first try of such approach in our public API.