Find the closest unvisited visible home
I don't see why you use a HashMap (or any Map) at all.

What I'd do is:


Get all the homes
Filter all the homes to only get those which are unvisited
Get the home that is closest


The home that you get will either be visible, or it won't be visible. If it is not visible, there won't be any other visible homes either.

Combining this with @Vogel's suggestion of using Set the code would go something like this:

Set&lt;Home&gt; visitedHomes = me.getVisitedHomes();
Set&lt;Home&gt; allHomes = getHomes();
Optional&lt;Home&gt; result = allHomes.stream().parallel()
    .filter(home -&gt; !visitedHomes.contains(home))
    .min(Comparator.comparingInt(home -&gt; range(me, home)))
    .map(result -&gt; range(me, result) &lt;= VISIBLE_ZONE ? result : null);


And then you can choose between either returning the optional:

return result;


or returning null if there is no match:

return result.orElse(null);