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=20455e8a5e2b8633d4d783a5e1e26fed46e2c602;hpb=20807d81708bd33b3b5a4616fadcf3ae91bf9508;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 20455e8..29e9959 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/Transformations.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/Transformations.java @@ -17,42 +17,52 @@ package org.wamblee.xmlrouter.impl; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.atomic.AtomicLong; import org.wamblee.xmlrouter.common.Id; import org.wamblee.xmlrouter.config.Transformation; +/** + * This class manages transformations and computes the shortest transformations + * paths based on the provided transformations. + * + * @author Erik Brakkee + * + */ public class Transformations { - private AtomicLong sequenceNumber; - private Map transformations; + private Map, Transformation> transformations; private List vertices; private TransformationPath[][] matrix; private Map> sequences; + /** + * Construct the transformations. + */ public Transformations() { - sequenceNumber = new AtomicLong(1); - transformations = new LinkedHashMap(); + transformations = new LinkedHashMap, Transformation>(); vertices = new ArrayList(); matrix = new TransformationPath[0][0]; } - public Id addTransformation(Transformation aTransformation) { - long seqno = sequenceNumber.getAndIncrement(); - Id id = new Id(seqno); - transformations.put(seqno, - new RobustTransformation(id, aTransformation)); + public void replaceTransformations( + Map, Transformation> aTransformations) { + transformations = aTransformations; computeTransformationSequences(); - return id; } + /** + * Gets the possible target types based on an input type. + * + * @param aType + * Input type. + * @return Possible target types. + */ public Collection getPossibleTargetTypes(String aType) { int index = vertices.indexOf(aType); Set res = new HashSet(); @@ -94,6 +104,9 @@ public class Transformations { return matrix[i][j]; } + /** + * Computest the transformation sequences using Floyd's algorithm. + */ private void computeTransformationSequences() { vertices = new ArrayList(); @@ -144,15 +157,6 @@ public class Transformations { .size(); } - public void removeTransformation(Id aId) { - transformations.remove(aId.getId()); - computeTransformationSequences(); - } - - public Collection getTransformations() { - return Collections.unmodifiableCollection(transformations.values()); - } - @Override public String toString() { StringBuffer buf = new StringBuffer();