final int[] upperRow = {-(size+1), -size, -(size-1)};
final int[] sameRow = {-1, +1};
final int[] lowerRow = {size-1, size, size+1 };
final IntPredicate basePredicate = x -> x >= 0 && x < totalSize;
for(int i = 0; i < totalSize; ++i)
{
final int cur = i;
final int currentRowIndex = (cur / size) + 1; //plus 1 to make it start indexing at 1
//all exclusive indices
final int upperRowIndex = (currentRowIndex - 1) * size;
final int sameRowIndex = currentRowIndex * size;
final int lowerRowIndex = (currentRowIndex + 1) * size;
int innerIndex = 0;
final int bigIndex = i * 8;
innerIndex = findMatches(cur, upperRow, basePredicate.and(x-> x < upperRowIndex), bigIndex, innerIndex, list2);
innerIndex = findMatches(cur, sameRow, basePredicate.and(x-> x >= upperRowIndex && x < sameRowIndex), bigIndex, innerIndex, list2);
findMatches(cur, lowerRow, basePredicate.and(x-> x >= sameRowIndex && x < lowerRowIndex), bigIndex, innerIndex, list2);
}
return list2;
}