package etomica.graph.operations;

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

import etomica.graph.model.Edge;
import etomica.graph.model.Graph;

/**
 * Deletes all edges of a given color.  This is useful for e=f+1.  After using
 * substitution with an explicit 1-bond, you can use this class to delete the
 * resulting 1-bonds.
 * 
 * @author Andrew Schultz
 */
public class DeleteEdge implements Unary {

  public Set<Graph> apply(Set<Graph> argument, Parameters params) {

    assert (params instanceof DeleteEdgeParameters);
    Set<Graph> result = new HashSet<Graph>();
    for (Graph g : argument) {
      Set<Graph> newSet = apply(g, (DeleteEdgeParameters) params);
      if (newSet != null) {
        result.addAll(newSet);
      }
    }
    Unary isoFree = new IsoFree();
    return isoFree.apply(result, params);
  }

  public Set<Graph> apply(Graph g, DeleteEdgeParameters params) {

    Set<Graph> result = new HashSet<Graph>();
    Graph newGraph = g.copy();
    for (Edge edge : g.edges()) {
      if (edge.getColor() == params.color()) {
        byte fromNode = g.getFromNode(edge.getId());
        byte toNode = g.getToNode(edge.getId());
        newGraph.deleteEdge(fromNode, toNode);
      }
    }
    result.add(newGraph);
    return result;
  }
}
@@ -615,28 +615,19 @@
     
-Set%3CGraph%3E newSet = 
+result.add(
 appl
@@ -665,71 +665,11 @@
 ams)
-;%0A      if (newSet != null) %7B%0A        result.addAll(newSet
 );%0A
-  
     
@@ -678,85 +678,21 @@
     
-%7D%0A    Unary isoFree = new IsoFree();%0A    return isoFree.apply(result, params)
+return result
 ;%0A  
@@ -699,34 +699,29 @@
 %7D%0A%0A  public 
-Set%3C
 Graph
-%3E
  apply(Graph
@@ -760,54 +760,8 @@
  %7B%0A%0A
-    Set%3CGraph%3E result = new HashSet%3CGraph%3E();%0A
     
@@ -1041,45 +1041,21 @@
   re
-sult.add(newGraph);%0A    return result
+turn newGraph
 ;%0A  

method that takes a Graph can return a Graph