com.codepoetics.fluvius.tracing.TraceMapFlowVisitor Maven / Gradle / Ivy
package com.codepoetics.fluvius.tracing;
import com.codepoetics.fluvius.api.*;
import com.codepoetics.fluvius.api.scratchpad.Key;
import com.codepoetics.fluvius.api.tracing.TraceMap;
import java.util.*;
final class TraceMapFlowVisitor implements FlowVisitor {
@Override
public TraceMap visitSingle(UUID stepId, Set> requiredKeys, Key providedKey, Operation operation) {
return TraceMap.ofStep(stepId, toKeyNames(requiredKeys), providedKey.getName(), operation.getName());
}
@Override
public TraceMap visitSequence(UUID stepId, Set> requiredKeys, Key providedKey, List items) {
return TraceMap.ofSequence(stepId, toKeyNames(requiredKeys), providedKey.getName(), items);
}
@Override
public TraceMap visitBranch(UUID stepId, Set> requiredKeys, Key providedKey, TraceMap defaultBranch, List> conditionalBranches) {
Map children = new LinkedHashMap<>(conditionalBranches.size() + 1);
for (Conditional conditional : conditionalBranches) {
children.put(
conditional.getCondition().getDescription(),
conditional.getValue());
}
return TraceMap.ofBranch(stepId, toKeyNames(requiredKeys), providedKey.getName(), defaultBranch, children);
}
private Set toKeyNames(Set> keys) {
Set result = new HashSet<>(keys.size());
for (Key> key : keys) {
result.add(key.getName());
}
return result;
}
@Override
public Condition visitCondition(Condition condition) {
return condition;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy