public ArrayList < DensityGrid > getNeighbours ( ) { ArrayList < DensityGrid > neighbours = new ArrayList < DensityGrid > ( ) ; DensityGrid h ; int [ ] hCoord = this . getCoordinates ( ) ; for ( int i = 0 ; i < this . dimensions ; i ++ ) { hCoord [ i ] = hCoord [ i ] - 1 ; h = new DensityGrid ( hCoord ) ; neighbours . add ( h ) ; hCoord [ i ] = hCoord [ i ] + 2 ; h = new DensityGrid ( hCoord ) ; neighbours . add ( h ) ; hCoord [ i ] = hCoord [ i ] - 1 ; } return neighbours ; }
Generates an Array List of neighbours for this density grid by varying each coordinate by one in either direction . Does not test whether the generated neighbours are valid as DensityGrid is not aware of the number of partitions in each dimension .