docs: @SuppressWarnings("unchecked")
      private void restoreDescendantComponentStates(UIComponent parent, boolean iterateFacets, Object state,
                                                    boolean restoreChildFacets)
      {
          int descendantStateIndex = -1;
          List<? extends Object[]> stateCollection = null;
          
          if (iterateFacets && parent.getFacetCount() > 0)
          {
              Iterator<UIComponent> childIterator = parent.getFacets().values().iterator();
              
              while (childIterator.hasNext())
              {
                  UIComponent component = childIterator.next();
  
                  // reset the client id (see spec 3.1.6)
                  component.setId(component.getId());
                  if (!component.isTransient())
                  {
                      if (descendantStateIndex == -1)
                      {
                          stateCollection = ((List<? extends Object[]>) state);
                          descendantStateIndex = stateCollection.isEmpty() ? -1 : 0;
                      }
                      
                      if (descendantStateIndex != -1 && descendantStateIndex < stateCollection.size())
                      {
                          Object[] object = stateCollection.get(descendantStateIndex);
                          if (object[0] != null && component instanceof EditableValueHolder)
                          {
                              ((SavedState) object[0]).restoreState((EditableValueHolder) component);
                          }
                          // If there is descendant state to restore, call it recursively, otherwise
                          // it is safe to skip iteration.
                          if (object[1] != null)
                          {
                              restoreDescendantComponentStates(component, restoreChildFacets, object[1], true);
                          }
                          else
                          {
                              restoreDescendantComponentWithoutRestoreState(component, restoreChildFacets, true);
                          }
                      }
                      else
                      {
                          restoreDescendantComponentWithoutRestoreState(component, restoreChildFacets, true);
                      }
                      descendantStateIndex++;
                  }
              }
          }
          
          if (parent.getChildCount() > 0)
          {
              for (int i = 0; i < parent.getChildCount(); i++)
              {
                  UIComponent component = parent.getChildren().get(i);
  
                  // reset the client id (see spec 3.1.6)
                  component.setId(component.getId());
                  if (!component.isTransient())
                  {
                      if (descendantStateIndex == -1)
                      {
                          stateCollection = ((List<? extends Object[]>) state);
                          descendantStateIndex = stateCollection.isEmpty() ? -1 : 0;
                      }
                      
                      if (descendantStateIndex != -1 && descendantStateIndex < stateCollection.size())
                      {
                          Object[] object = stateCollection.get(descendantStateIndex);
                          if (object[0] != null && component instanceof EditableValueHolder)
                          {
                              ((SavedState) object[0]).restoreState((EditableValueHolder) component);
                          }
                          // If there is descendant state to restore, call it recursively, otherwise
                          // it is safe to skip iteration.
                          if (object[1] != null)
                          {
                              restoreDescendantComponentStates(component, restoreChildFacets, object[1], true);
                          }
                          else
                          {
                              restoreDescendantComponentWithoutRestoreState(component, restoreChildFacets, true);
                          }
                      }
                      else
                      {
                          restoreDescendantComponentWithoutRestoreState(component, restoreChildFacets, true);
                      }
                      descendantStateIndex++;
                  }
              }
          }
      }