* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.xmlrouter.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
import org.wamblee.xmlrouter.common.Id;
import org.wamblee.xmlrouter.config.Transformation;
public class Transformations {
- private AtomicInteger sequenceNumber;
- private Map<Integer, Transformation> transformations;
+ private AtomicLong sequenceNumber;
+ private Map<Id<Transformation>, Transformation> transformations;
private List<String> vertices;
private TransformationPath[][] matrix;
private Map<String, List<TransformationPath>> sequences;
public Transformations() {
- sequenceNumber = new AtomicInteger(1);
- transformations = new LinkedHashMap<Integer, Transformation>();
+ sequenceNumber = new AtomicLong(1);
+ transformations = new LinkedHashMap<Id<Transformation>, Transformation>();
vertices = new ArrayList<String>();
matrix = new TransformationPath[0][0];
}
public Id<Transformation> addTransformation(Transformation aTransformation) {
- int seqno = sequenceNumber.getAndIncrement();
+ long seqno = sequenceNumber.getAndIncrement();
Id<Transformation> id = new Id<Transformation>(seqno);
- transformations.put(seqno,
- new RobustTransformation(id, aTransformation));
+ transformations.put(id, new RobustTransformation(id, aTransformation));
computeTransformationSequences();
return id;
}
*/
public TransformationPath getPath(String aFrom, String aTo) {
int i = vertices.indexOf(aFrom);
- if (i == -1) {
+ if (i < 0) {
if (aFrom.equals(aTo)) {
return new TransformationPath();
}
}
int j = vertices.indexOf(aTo);
+ if (j < 0) {
+ return null;
+ }
return matrix[i][j];
}
}
public void removeTransformation(Id<Transformation> aId) {
- transformations.remove(aId.getId());
+ transformations.remove(aId);
computeTransformationSequences();
}
- public Collection<Transformation> getTransformations() {
- return Collections.unmodifiableCollection(transformations.values());
+ public Collection<Id<Transformation>> getTransformations() {
+ return Collections.unmodifiableCollection(transformations.keySet());
+ }
+
+ public Transformation getTransformation(Id<Transformation> aId) {
+ return transformations.get(aId);
}
@Override