@Nullable
    private AllocatedGroupRange getNextAvailableGroupRange(final int size,
                                                           @NonNull final AllocatedGroupRange bound,
                                                           @NonNull final List<AllocatedGroupRange> ranges) {
        AllocatedGroupRange bestRange = null;
        int lastUpperBound = bound.lowAddress - 1;

        // Go through all ranges looking for a gaps.
        for (AllocatedGroupRange range : ranges) {
            if (lastUpperBound + size < range.lowAddress) {
                return new AllocatedGroupRange(lastUpperBound + 1, lastUpperBound + size);
            }

            // If the space exists, but it's not as big as requested, compare
            // it with the best range so far and replace if it's bigger.
            if (range.lowAddress - lastUpperBound > 1) {
                final AllocatedGroupRange newRange = new AllocatedGroupRange(lastUpperBound + 1, range.lowAddress - 1);
                if (bestRange == null || newRange.range() > bestRange.range()) {
                    bestRange = newRange;
                }
            }
            lastUpperBound = range.highAddress;
        }

        // If if we didn't return earlier, check after the last range.
        if (lastUpperBound + size < bound.highAddress) {
            return new AllocatedGroupRange(lastUpperBound + 1, lastUpperBound + size - 1);
        }
        // The gap of requested size hasn't been found. Return the best found.
        return bestRange;
    }
Returns the next available scene range for a given size

@param rangeSize Range size
mesh/src/main/java/no/nordicsemi/android/mesh/MeshNetwork.java