package org.hanuna.gitalk.commitgraph.hides;

import org.hanuna.gitalk.commitmodel.Commit;
import org.hanuna.gitalk.commitmodel.CommitsModel;
import org.hanuna.gitalk.common.ReadOnlyList;
import org.hanuna.gitalk.common.calculatemodel.calculator.AbstractCalculator;
import org.jetbrains.annotations.NotNull;

/**
 * @author erokhins
 */
public class HideCommitsCalculator extends AbstractCalculator<MutableHideCommits, HideCommits> {
    private final CommitsModel commitsModel;

    public HideCommitsCalculator(CommitsModel commitsModel) {
        this.commitsModel = commitsModel;
    }

    @NotNull
    @Override
    public HideCommits getFirst() {
        return MutableHideCommits.getEmpty(0);
    }

    @NotNull
    @Override
    protected MutableHideCommits createMutable(HideCommits prev) {
        return MutableHideCommits.create(prev);
    }

    @Override
    protected int size() {
        return commitsModel.size();
    }

    @NotNull
    protected MutableHideCommits oneStep(MutableHideCommits hideCommits) {
        ReadOnlyList<Commit> hides = commitsModel.hidesCommits(hideCommits.getRowIndex());
        ReadOnlyList<Commit> shows = commitsModel.showsCommits(hideCommits.getRowIndex());
        for (Commit hide : hides) {
            hideCommits.add(hide);
        }
        for (Commit show : shows) {
            hideCommits.remove(show);
        }
        hideCommits.setRowIndex(hideCommits.getRowIndex() + 1);
        return hideCommits;
    }
}

@@ -181,16 +181,68 @@
 lyList;%0A
+import org.hanuna.gitalk.common.SimpleReadOnlyList;%0A
 import o
@@ -1069,24 +1069,75 @@
 deCommits) %7B
+%0A%0A        int rowIndex = hideCommits.getRowIndex();
 %0A        Rea
@@ -1192,33 +1192,16 @@
 its(
-hideCommits.getR
+r
 owIndex
-()
 );%0A 
@@ -1237,65 +1237,186 @@
 hows
- = commitsModel.showsCommits(hideCommits.getRowIndex
+;%0A        if (rowIndex %3C size() - 1) %7B%0A            shows = commitsModel.showsCommits(rowIndex + 1);%0A        %7D else %7B%0A            shows = SimpleReadOnlyList.getEmpty
 ()
-)
 ;%0A
+        %7D%0A
     
@@ -1612,33 +1612,16 @@
 dex(
-hideCommits.getR
+r
 owIndex
-()
  + 1

fix HideCommitsCalculator