Search in sources :

Example 1 with IForumItemFlat

use of forpdateam.ru.forpda.api.forum.interfaces.IForumItemFlat in project ForPDA by RadiationX.

the class Forum method transformToTree.

public void transformToTree(Collection<? extends IForumItemFlat> list, ForumItemTree rootForum) {
    List<ForumItemTree> parentsList = new ArrayList<>();
    ForumItemTree lastParent = rootForum;
    parentsList.add(lastParent);
    for (IForumItemFlat item : list) {
        ForumItemTree newItem = new ForumItemTree(item);
        if (item.getLevel() <= lastParent.getLevel()) {
            // Удаление элементов, учитывая случай с резким скачком уровня вложенности
            for (int i = 0; i < (lastParent.getLevel() - item.getLevel() + 1); i++) parentsList.remove(parentsList.size() - 1);
            lastParent = parentsList.get(parentsList.size() - 1);
        }
        lastParent.addForum(newItem);
        if (item.getLevel() > lastParent.getLevel()) {
            lastParent = newItem;
            parentsList.add(lastParent);
        }
    }
    parentsList.clear();
}
Also used : ForumItemTree(forpdateam.ru.forpda.api.forum.models.ForumItemTree) ArrayList(java.util.ArrayList) IForumItemFlat(forpdateam.ru.forpda.api.forum.interfaces.IForumItemFlat)

Aggregations

IForumItemFlat (forpdateam.ru.forpda.api.forum.interfaces.IForumItemFlat)1 ForumItemTree (forpdateam.ru.forpda.api.forum.models.ForumItemTree)1 ArrayList (java.util.ArrayList)1