Switch Adjacent Blocks in tiled terrain

Hi!

I am trying to write a code to draw a tiled terrain on screen.

The problem occurs when I try, for every block, to check adjacent blocks and switch them to certain block if current block is, for example, type Water.

I think the algorithm is ok, but my code doesn’t work.

._.

Is there a way to edit my code properly?
Or maybe you can share with me another working algorithm?

Here the Terrain class and the Layer class.

Sorry for my bad english, tell me if something isn’t clear.