package org.hanuna.gitalk.graph.new_mutable;

import org.hanuna.gitalk.graph.elements.GraphElement;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
 * @author erokhins
 */
public class ElementVisibilityController {
    private final Set<GraphElement> hiddenElements = new HashSet<GraphElement>();

    public boolean isVisible(@NotNull GraphElement graphElement) {
        return !hiddenElements.contains(graphElement);
    }

    public void hide(@NotNull Collection<GraphElement> graphElements) {
        hiddenElements.addAll(graphElements);
    }

    public void show(@NotNull Collection<GraphElement> graphElements) {
        hiddenElements.removeAll(graphElements);
    }
}

@@ -39,16 +39,61 @@
 table;%0A%0A
+import org.hanuna.gitalk.commitmodel.Commit;%0A
 import o
@@ -124,28 +124,20 @@
 lements.
-GraphElement
+Edge
 ;%0Aimport
@@ -145,94 +145,139 @@
 org.
-jetbrains.annotations.NotNull
+hanuna.gitalk.graph.elements.GraphElement
 ;%0A
-%0A
 import 
-java.util.Collection;%0Aimport java.util.HashSet;
+org.hanuna.gitalk.graph.elements.Node;%0Aimport org.jetbrains.annotations.NotNull;%0A
 %0Aimp
@@ -290,19 +290,17 @@
 va.util.
-Set
+*
 ;%0A%0A/**%0A 
@@ -391,28 +391,20 @@
 Set%3C
-GraphElement
+Node
 %3E hidden
 Elem
@@ -399,23 +399,20 @@
 %3E hidden
-Element
+Node
 s = new 
@@ -423,145 +423,685 @@
 Set%3C
-GraphElement%3E();%0A%0A    public boolean isVisible(@NotNull GraphElement graphElement) %7B%0A        return !hiddenElements.contains(graphElement
+Node%3E();%0A    private final Collection%3CCommit%3E visibleCommits = new HashSet%3CCommit%3E();%0A    private boolean showAllBranchesFlag = true;%0A%0A    public boolean isVisible(@NotNull GraphElement graphElement) %7B%0A        Node node = graphElement.getNode();%0A        if (node != null) %7B%0A            return isVisibleNode(node);%0A        %7D else %7B%0A            Edge edge = graphElement.getEdge();%0A            assert edge != null;%0A            return isVisible(edge.getUpNode()) && isVisible(edge.getDownNode());%0A        %7D%0A    %7D%0A%0A    private boolean isVisibleNode(@NotNull Node node) %7B%0A        return !hiddenNodes.contains(node) && (showAllBranchesFlag %7C%7C visibleCommits.contains(node.getCommit())
 );%0A 
@@ -1098,32 +1098,33 @@
 mit()));%0A    %7D%0A%0A
+%0A
     public void 
@@ -1144,36 +1144,28 @@
  Collection%3C
-GraphElement
+Node
 %3E graphEleme
@@ -1185,23 +1185,20 @@
   hidden
-Element
+Node
 s.addAll
@@ -1262,17 +1262,23 @@
 lection%3C
-G
+Node%3E g
 raphElem
@@ -1280,18 +1280,51 @@
 hElement
-%3E 
+s) %7B%0A        hiddenNodes.removeAll(
 graphEle
@@ -1333,64 +1333,354 @@
 nts)
- %7B
+;
 %0A    
+%7D%0A%0A
     
-hiddenElements.removeAll(graphElements)
+public void setShowAllBranchesFlag(boolean showAllBranchesFlag) %7B%0A        this.showAllBranchesFlag = showAllBranchesFlag;%0A    %7D%0A%0A    public void setVisibleCommits(@NotNull List%3CCommit%3E visibleCommits) %7B%0A        this.visibleCommits.clear();%0A        this.visibleCommits.addAll(visibleCommits);%0A        showAllBranchesFlag = false
 ;%0A    %7D%0A
 %7D%0A
@@ -1677,10 +1677,12 @@
 ;%0A    %7D%0A
+%0A%0A
 %7D%0A

add branch show/hide capability