use of org.kie.dmn.model.v1_1.ItemDefinition in project drools by kiegroup.
the class ItemDefinitionDependenciesTest method testOrdering4.
@Test
public void testOrdering4() {
ItemDefinition _TypeDecisionA1 = build("TypeDecisionA1");
ItemDefinition _TypeDecisionA2_x = build("TypeDecisionA2.x", _TypeDecisionA1);
ItemDefinition _TypeDecisionA3 = build("TypeDecisionA3", _TypeDecisionA2_x);
ItemDefinition _TypeDecisionB1 = build("TypeDecisionB1");
ItemDefinition _TypeDecisionB2_x = build("TypeDecisionB2.x", _TypeDecisionB1);
ItemDefinition _TypeDecisionB3 = build("TypeDecisionB3", _TypeDecisionB2_x, _TypeDecisionA3);
ItemDefinition _TypeDecisionC1 = build("TypeDecisionC1", _TypeDecisionA3, _TypeDecisionB3);
ItemDefinition _TypeDecisionC4 = build("TypeDecisionC4");
List<ItemDefinition> originalList = Arrays.asList(new ItemDefinition[] { _TypeDecisionA1, _TypeDecisionA2_x, _TypeDecisionA3, _TypeDecisionB1, _TypeDecisionB2_x, _TypeDecisionB3, _TypeDecisionC1, _TypeDecisionC4 });
List<ItemDefinition> orderedList = orderingStrategy(originalList);
assertTrue("Index of _TypeDecisionA1 < _TypeDecisionA2_x", orderedList.indexOf(_TypeDecisionA1) < orderedList.indexOf(_TypeDecisionA2_x));
assertTrue("Index of _TypeDecisionA2_x < _TypeDecisionA3", orderedList.indexOf(_TypeDecisionA2_x) < orderedList.indexOf(_TypeDecisionA3));
assertTrue("Index of _TypeDecisionA3 < _TypeDecisionB3", orderedList.indexOf(_TypeDecisionA3) < orderedList.indexOf(_TypeDecisionB3));
assertTrue("Index of _TypeDecisionA3 < _TypeDecisionC1", orderedList.indexOf(_TypeDecisionA3) < orderedList.indexOf(_TypeDecisionC1));
assertTrue("Index of _TypeDecisionB1 < _TypeDecisionB2_x", orderedList.indexOf(_TypeDecisionB1) < orderedList.indexOf(_TypeDecisionB2_x));
assertTrue("Index of _TypeDecisionB2_x < _TypeDecisionB3", orderedList.indexOf(_TypeDecisionB2_x) < orderedList.indexOf(_TypeDecisionB3));
assertTrue("Index of _TypeDecisionB3 < _TypeDecisionC1", orderedList.indexOf(_TypeDecisionB3) < orderedList.indexOf(_TypeDecisionC1));
}
use of org.kie.dmn.model.v1_1.ItemDefinition in project drools by kiegroup.
the class ItemDefinitionDependenciesTest method testGeneric.
@Test
public void testGeneric() {
ItemDefinition a = build("a");
ItemDefinition b = build("b");
ItemDefinition c = build("c", a, b);
ItemDefinition d = build("d", c);
List<ItemDefinition> originalList = Arrays.asList(new ItemDefinition[] { d, c, b, a });
List<ItemDefinition> orderedList = orderingStrategy(originalList);
assertThat(orderedList.subList(0, 2), containsInAnyOrder(a, b));
assertThat(orderedList.subList(2, 4), contains(c, d));
}
use of org.kie.dmn.model.v1_1.ItemDefinition in project drools by kiegroup.
the class ItemDefinitionDependenciesSorter method sort.
/**
* Return a new list of ItemDefinition sorted by dependencies (required dependencies comes first)
*/
public List<ItemDefinition> sort(List<ItemDefinition> ins) {
// In a graph A -> B -> {C, D}
// showing that A requires B, and B requires C,D
// then a depth-first visit would satisfy required ordering, for example a valid depth first visit is also a valid sort here: C, D, B, A.
Collection<ItemDefinition> visited = new ArrayList<>(ins.size());
List<ItemDefinition> dfv = new ArrayList<>(ins.size());
for (ItemDefinition node : ins) {
if (!visited.contains(node)) {
dfVisit(node, ins, visited, dfv);
}
}
return dfv;
}
use of org.kie.dmn.model.v1_1.ItemDefinition in project drools by kiegroup.
the class ItemDefinitionDependenciesSorter method displayDependencies.
public static void displayDependencies(List<ItemDefinition> ins, String namespaceURI) {
for (ItemDefinition in : ins) {
System.out.println(in.getName());
List<ItemDefinition> others = new ArrayList<>(ins);
others.remove(in);
for (ItemDefinition other : others) {
QName otherQName = new QName(namespaceURI, other.getName());
if (directFind(in, otherQName)) {
System.out.println(" direct depends on: " + other.getName());
} else if (recurseFind(in, otherQName)) {
System.out.println(" indir. depends on: " + other.getName());
}
}
}
}
use of org.kie.dmn.model.v1_1.ItemDefinition in project drools by kiegroup.
the class ItemDefinitionDependenciesSorter method dfVisit.
/**
* Performs a depth first visit, but keeping a separate reference of visited/visiting nodes, _also_ to avoid potential issues of circularities.
*/
private void dfVisit(ItemDefinition node, List<ItemDefinition> allNodes, Collection<ItemDefinition> visited, List<ItemDefinition> dfv) {
visited.add(node);
List<ItemDefinition> neighbours = allNodes.stream().filter(// filter out `node`
n -> !n.getName().equals(node.getName())).filter(// I pick from allNodes, those referenced by this `node`. Only neighbours of `node`, because N is referenced by NODE.
n -> recurseFind(node, new QName(modelNamespace, n.getName()))).collect(Collectors.toList());
for (ItemDefinition n : neighbours) {
if (!visited.contains(n)) {
dfVisit(n, allNodes, visited, dfv);
}
}
dfv.add(node);
}
Aggregations