How do I calculate Boolean value in a list of list? Each element in a list has a nested list in it. Below is the code snippet

```
class ChildComponent {
    List<ChildComponent> childComponents = new ArrayList<>();
    Boolean notificationEnabled = Boolean.FALSE;
    String name;

    //respective Gettters/Setters
}

class ModelItem {
    List<ChildComponent> components = new ArrayList<>();
    Boolean alertUser;
}

```

`ModelItem` have a `list` of components. Each component in the components `list` have a `notificationEnabled` flag. Also, each component has a list of `ChildComponent`.

**`alertUser` should be set to `true`** in below cases:

* if any of the `ChildComponent` in the `components` have `notificationEnabled` set to `true`
* Any of the elements in `List<ChildComponent> childComponents` has `notificationEnabled` set to `true`

So, basically, if any of the `Components` has `notificationEnabled` set to `true` then `alertUser` should be set to `true`

How to do it?

`modelItem.components.stream().flatMap(a -> a.childComponents.stream())` does not work as it check. More details in the snippet

Below is the sample code:

```
public static void main(String[] args) {

    ModelItem modelItem1 = new ModelItem();
    modelItem1.components.add(createC1());
    modelItem1.components.add(createC2());

    updateAlert(modelItem1);
}

**// does not work. It only check childComponents**
private static void updateAlert(ModelItem modelItem) {
    boolean anyMatchFilterPromptAtRun = modelItem.components.stream().flatMap(a -> a.childComponents.stream())
            .anyMatch(b -> b.notificationEnabled.equals(Boolean.TRUE));
    modelItem.alertUser = Boolean.valueOf(anyMatchFilterPromptAtRun);
}

private static ChildComponent createC1() {
    ChildComponent c1_1 = new ChildComponent();
    c1_1.name = "c1_1";
    c1_1.notificationEnabled = false;

    ChildComponent c1_2 = new ChildComponent();
    c1_2.name = "c1_2";
    c1_2.notificationEnabled = true;

    // main C2
    ChildComponent c1 = new ChildComponent();
    c1.name = "C1";
    c1.childComponents = Arrays.asList(c1_1, c1_2) ;
    c1.notificationEnabled = false;

    return c1;
}

private static ChildComponent createC2() {
    ChildComponent c1_1 = new ChildComponent();
    c1_1.name = "c1_1";
    c1_1.notificationEnabled = false;

    ChildComponent c1_2 = new ChildComponent();
    c1_2.name = "c1_2";
    c1_2.notificationEnabled = true;

    // main C1
    ChildComponent c1 = new ChildComponent();
    c1.name = "C1";
    c1.childComponents = Arrays.asList(c1_1, c1_2) ;
    c1.notificationEnabled = false;

    return c1;
}

```

Below is the sample structure

```
{
  "components": [
    {
      "name": "C1",
      "notificationEnabled": false,
      "childComponents": [
        {
          "name": "c1_1",
          "notificationEnabled": false,
          "childComponents": []
        },
        {
          "name": "c1_2",
          "notificationEnabled": true,
          "childComponents": []
        }
      ]
    },
    {
      "name": "C1",
      "notificationEnabled": false,
      "childComponents": [
        {
          "name": "c1_1",
          "notificationEnabled": false,
          "childComponents": []
        },
        {
          "name": "c1_2",
          "notificationEnabled": true,
          "childComponents": []
        }
      ]
    }
  ]
}

```