@ Override public Set < Island > getIslands ( ) { Map < Coordinate , Island > coordinateMapper = new HashMap <> ( ) ; List < Coordinate > allMatches = allMatches ( ) ; for ( Coordinate c : allMatches ) { // LOG.debug("coordinate {}", c); addToIslands ( coordinateMapper , c ) ; } Set < Coordinate > smallestIslandsCoordinates = new HashSet <> ( allMatches ) ; smallestIslandsCoordinates . removeAll ( coordinateMapper . keySet ( ) ) ; for ( Coordinate coordinate : smallestIslandsCoordinates ) { Island island = new Island ( ) ; island . add ( coordinate ) ; coordinateMapper . put ( coordinate , island ) ; } return new HashSet <> ( coordinateMapper . values ( ) ) ; }
we don t need to check the lower right neighbor .