X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FTransformations.java;h=29e995916e78515fad607eb797ccc7923fd514f1;hb=19413a6699295b4bbebc1b3bdb9838fd4370e581;hp=c297fac787ce5ea66ca66339435fdd85bc59a8c7;hpb=f77e29e9ae2505009ffc9270f4c4adfde331fa62;p=xmlrouter diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/Transformations.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/Transformations.java index c297fac..29e9959 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/Transformations.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/Transformations.java @@ -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 transformations; + private Map, Transformation> transformations; private List vertices; private TransformationPath[][] matrix; @@ -45,52 +45,15 @@ public class Transformations { * Construct the transformations. */ public Transformations() { - transformations = new ConfigImpl() { - @Override - public Transformation wrap(Id aId, - Transformation aType) { - return new RobustTransformation(aId, aType); - } - }; + transformations = new LinkedHashMap, Transformation>(); vertices = new ArrayList(); matrix = new TransformationPath[0][0]; } - public Config getTransformationConfig() { - return new Config() { - @Override - public Id add(Transformation aT) { - return addTransformation(aT); - } - - @Override - public Transformation get(Id aId) { - return transformations.get(aId); - } - - @Override - public Collection> ids() { - return transformations.ids(); - } - - @Override - public boolean remove(Id 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 addTransformation(Transformation aTransformation) { - Id id = transformations.add(aTransformation); + public void replaceTransformations( + Map, Transformation> aTransformations) { + transformations = aTransformations; computeTransformationSequences(); - return id; } /** @@ -149,8 +112,7 @@ public class Transformations { // Obtain possible starting points. Set v = new HashSet(); - for (Id 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 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 aId) { - transformations.remove(aId); - computeTransformationSequences(); - } - @Override public String toString() { StringBuffer buf = new StringBuffer();