Issue porting dart dungeon generator into Java

Hi all,

Recently I found a dungeon generator written in dart and have attempted to port it into Java. Here’s the dart source: https://github.com/munificent/hauberk/blob/db360d9efa714efb6d937c31953ef849c7394a39/lib/src/content/dungeon.dart

So far I’ve managed to successfully randomly place rooms and grow a maze around them. But I’ve hit an issue with the connectRegions method. More specifically lines 211 and 229. I’m struggling to interpret them into Java.

Here’s my current method: http://pastebin.com/W9WTEkQT

My methods spits out an array index out of bounds error at line 48 of the pastebin link. I’m probably doing something very stupid, another pair of eyes would help.

Any ideas where I’m going wrong?

Edit: Wrote this on mobile, line numbers were wrong. Corrected now.