private List<ExpandableWrapper<P,C>> generateFlattenedParentChildList(List<P> parentList,Map<P,Boolean> savedLastExpansionState){
  List<ExpandableWrapper<P,C>> flatItemList=new ArrayList<>();
  int parentCount=parentList.size();
  for (int i=0; i < parentCount; i++) {
    P parent=parentList.get(i);
    Boolean lastExpandedState=savedLastExpansionState.get(parent);
    boolean shouldExpand=lastExpandedState == null ? parent.isInitiallyExpanded() : lastExpandedState;
    generateParentWrapper(flatItemList,parent,shouldExpand);
  }
  return flatItemList;
}

private List < ExpandableWrapper < P , C > > generateFlattenedParentChildList ( List < P > parentList , Map < P , Boolean > savedLastExpansionState ) { List < ExpandableWrapper < P , C > > flatItemList = new ArrayList < > ( ) ; int parentCount = parentList . size ( ) ; for ( int i = 0 ; i < parentCount ; i ++ ) { P parent = parentList . get ( i ) ; Boolean lastExpandedState = savedLastExpansionState . get ( parent ) ; boolean shouldExpand = lastExpandedState == null ? parent . isInitiallyExpanded ( ) : lastExpandedState ; generateParentWrapper ( flatItemList , parent , shouldExpand ) ; } return flatItemList ; }
generates a full list of all parents and their children , in order . uses map to preserve last expanded state .
