package net.fortytwo.smsn.brain.io.edges;

import net.fortytwo.smsn.brain.io.BrainWriter;
import net.fortytwo.smsn.brain.io.Format;
import net.fortytwo.smsn.brain.model.Atom;
import net.fortytwo.smsn.brain.model.AtomGraph;
import net.fortytwo.smsn.brain.model.AtomList;

import java.io.IOException;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.List;

public class EdgeWriter extends BrainWriter {

    @Override
    public List<Format> getFormats() {
        return Arrays.asList(EdgeTSVFormat.getInstance());
    }

    @Override
    public void doExport(Context context) throws IOException {
        AtomGraph sourceGraph = context.getFilteredGraph();
        PrintStream p = new PrintStream(context.getDestStream());

        p.println("from\tto");

        for (Atom a : sourceGraph.getAllAtoms()) {
            if (null != a) {
                AtomList l = a.getNotes();
                while (null != l) {
                    p.print(a.getId());
                    p.print('\t');
                    p.print(l.getFirst().getId());
                    p.print('\n');
                    l = l.getRest();
                }
            }
        }
    }
}

@@ -262,16 +262,61 @@
 tomList;
+%0Aimport net.fortytwo.smsn.brain.model.Filter;
 %0A%0Aimport
@@ -704,16 +704,12 @@
 .get
-Filtered
+Atom
 Grap
@@ -778,16 +778,61 @@
 ream());
+%0A        Filter filter = context.getFilter();
 %0A%0A      
@@ -875,17 +875,24 @@
 r (Atom 
-a
+fromAtom
  : sourc
@@ -939,17 +939,54 @@
 null != 
-a
+fromAtom && filter.isVisible(fromAtom)
 ) %7B%0A    
@@ -1010,17 +1010,24 @@
 ist l = 
-a
+fromAtom
 .getNote
@@ -1091,63 +1091,92 @@
     
-p.print(a.getId());%0A                    p.print('%5Ct');%0A
+Atom toAtom = l.getFirst();%0A                    if (filter.isVisible(toAtom)) %7B%0A    
     
@@ -1195,36 +1195,37 @@
     
-p.
 print
-(l.getFirst().getId()
+Edge(p, fromAtom, toAtom
 );%0A 
@@ -1247,22 +1247,9 @@
     
-p.print('%5Cn');
+%7D
 %0A   
@@ -1329,11 +1329,222 @@
  %7D%0A    %7D
+%0A%0A    private void printEdge(final PrintStream p, final Atom fromAtom, final Atom toAtom) %7B%0A        p.print(fromAtom.getId());%0A        p.print('%5Ct');%0A        p.print(toAtom.getId());%0A        p.print('%5Cn');%0A    %7D
 %0A%7D%0A

Apply custom filtering in EdgeWriter