Now using RouterConfig internally inside the XML Router.
[xmlrouter] / impl / src / main / java / org / wamblee / xmlrouter / impl / Transformations.java
index c297fac787ce5ea66ca66339435fdd85bc59a8c7..29e995916e78515fad607eb797ccc7923fd514f1 100644 (file)
@@ -18,12 +18,12 @@ package org.wamblee.xmlrouter.impl;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import org.wamblee.xmlrouter.common.Id;
-import org.wamblee.xmlrouter.config.Config;
 import org.wamblee.xmlrouter.config.Transformation;
 
 /**
@@ -35,7 +35,7 @@ import org.wamblee.xmlrouter.config.Transformation;
  */
 public class Transformations {
 
-    private Config<Transformation> transformations;
+    private Map<Id<Transformation>, Transformation> transformations;
     private List<String> vertices;
     private TransformationPath[][] matrix;
 
@@ -45,52 +45,15 @@ public class Transformations {
      * Construct the transformations.
      */
     public Transformations() {
-        transformations = new ConfigImpl<Transformation>() {
-            @Override
-            public Transformation wrap(Id<Transformation> aId,
-                Transformation aType) {
-                return new RobustTransformation(aId, aType);
-            }
-        };
+        transformations = new LinkedHashMap<Id<Transformation>, Transformation>();
         vertices = new ArrayList<String>();
         matrix = new TransformationPath[0][0];
     }
 
-    public Config<Transformation> getTransformationConfig() {
-        return new Config<Transformation>() {
-            @Override
-            public Id<Transformation> add(Transformation aT) {
-                return addTransformation(aT);
-            }
-
-            @Override
-            public Transformation get(Id<Transformation> aId) {
-                return transformations.get(aId);
-            }
-
-            @Override
-            public Collection<Id<Transformation>> ids() {
-                return transformations.ids();
-            }
-
-            @Override
-            public boolean remove(Id<Transformation> aId) {
-                return transformations.remove(aId);
-            }
-        };
-    }
-
-    /**
-     * Adds a transformation. Leads to recomputation of shortest paths.
-     * 
-     * @param aTransformation
-     *            Transformation to add.
-     * @return Id of the transformation.
-     */
-    public Id<Transformation> addTransformation(Transformation aTransformation) {
-        Id<Transformation> id = transformations.add(aTransformation);
+    public void replaceTransformations(
+        Map<Id<Transformation>, Transformation> aTransformations) {
+        transformations = aTransformations;
         computeTransformationSequences();
-        return id;
     }
 
     /**
@@ -149,8 +112,7 @@ public class Transformations {
 
         // Obtain possible starting points.
         Set<String> v = new HashSet<String>();
-        for (Id<Transformation> id : transformations.ids()) {
-            Transformation transformation = transformations.get(id);
+        for (Transformation transformation : transformations.values()) {
             v.add(transformation.getFromType());
             v.add(transformation.getToType());
         }
@@ -164,8 +126,7 @@ public class Transformations {
         for (int i = 0; i < nvertices; i++) {
             matrix[i][i] = new TransformationPath();
         }
-        for (Id<Transformation> id : transformations.ids()) {
-            Transformation transformation = transformations.get(id);
+        for (Transformation transformation : transformations.values()) {
             int from = vertices.indexOf(transformation.getFromType());
             int to = vertices.indexOf(transformation.getToType());
             TransformationPath path = new TransformationPath(transformation);
@@ -196,17 +157,6 @@ public class Transformations {
             .size();
     }
 
-    /**
-     * Removes a transformation.
-     * 
-     * @param aId
-     *            Id of the transformation.
-     */
-    public void removeTransformation(Id<Transformation> aId) {
-        transformations.remove(aId);
-        computeTransformationSequences();
-    }
-
     @Override
     public String toString() {
         StringBuffer buf = new StringBuffer();