@Nullable
    public Integer nextAvailableSceneNumber(Provisioner provisioner) throws IllegalArgumentException {
        if (provisioner.getAllocatedSceneRanges().isEmpty()) {
            throw new IllegalArgumentException("Please allocate a scene range to the provisioner!");
        }

        Collections.sort(scenes, sceneComparator);
        // Iterate through all nodes just once, while iterating over ranges.
        int index = 0;
        for (AllocatedSceneRange sceneRange : provisioner.getAllocatedSceneRanges()) {
            // Start from the beginning of the current range.
            int number = sceneRange.getFirstScene();

            // Iterate through nodes that weren't checked yet.
            int currentIndex = index;
            for (int i = currentIndex; i < scenes.size(); i++) {
                final Scene scene = scenes.get(i);
                index += i;

                // Skip scenes with number below the range.
                if (number > scene.getNumber()) {
                    continue;
                }

                // If we found a space before the current scene, return the scene number.
                if (number < scene.getNumber()) {
                    return number;
                }

                // Else, move the address to the next available address.
                number = scene.getNumber() + 1;

                // If the new address is outside of the range, go to the next one.
                if (number > sceneRange.getLastScene()) {
                    break;
                }
            }
            // If the range has available space, return the address.
            if (number <= sceneRange.getLastScene()) {
                return number;
            }
        }

        // No scene number was found :(
        return null;
    }
Returns the next available Scene number from the Provisioner's range
that can be assigned to a new Scene.

@param provisioner provisioner
@return The next available Scene number that can be assigned to a new Scene,
or null, if there are no more available numbers in the allocated range.
@throws IllegalArgumentException if there is no allocated scene range to the provisioner
mesh/src/main/java/no/nordicsemi/android/mesh/MeshNetwork.java