List of usage examples for org.apache.commons.scxml.model Assign getExpr
public String getExpr()
From source file:org.finra.datagenerator.engine.negscxml.NegSCXMLCommons.java
/** * Expands a NegPossibleState using the negative scenarios as well, multiple times for different numbers * and combinations of negative scenarios * * @param state the NegPossibleState to expand * @param bootStrap the list to add new NegPossibleStates found by expansion * @param negDegreesFreedom the max number of negative scenarios this expansion can add */// w w w. j a va 2 s . co m public void expandNegative(NegPossibleState state, List<NegPossibleState> bootStrap, int negDegreesFreedom) { TransitionTarget nextState = state.nextState; OnEntry entry = nextState.getOnEntry(); List<Action> actions = entry.getActions(); //determine which variables have positive assignments, negative assignments, or both Set<String> positiveOnlyVariables = new HashSet<>(); Set<String> hasNegativeVariables = new HashSet<>(); Map<String, Assign> positiveAssignments = new HashMap<>(); Map<String, NegativeAssign> negativeAssignments = new HashMap<>(); for (Action action : actions) { if (action instanceof Assign) { String variable = ((Assign) action).getName(); positiveAssignments.put(variable, (Assign) action); positiveOnlyVariables.add(variable); } else if (action instanceof NegativeAssign) { String variable = ((NegativeAssign) action).getName(); negativeAssignments.put(variable, (NegativeAssign) action); hasNegativeVariables.add(variable); } } for (String variable : hasNegativeVariables) { positiveOnlyVariables.remove(variable); } //produce core cartesian product from variables with only positive assignments List<Map<String, String>> productCore = new LinkedList<>(); productCore.add(new HashMap<>(state.variables)); for (String variable : positiveOnlyVariables) { Assign assign = positiveAssignments.get(variable); String expr = assign.getExpr(); productCore = takeProduct(productCore, variable, splitSet(expr)); } //produce the negative assignments from the positive core, from 1 assignment to negDegreesFreedom assignments for (int n = 1; n <= negDegreesFreedom; n++) { //find all combinations of choosing n negative variables in negativeAssignments List<Set<String>> completeChoices = new LinkedList<Set<String>>(); List<Set<String>> incompleteChoices = new LinkedList<Set<String>>(); Set<String> emptyChoice = new HashSet<String>(); incompleteChoices.add(emptyChoice); for (String variable : hasNegativeVariables) { List<Set<String>> newChoices = new LinkedList<Set<String>>(); for (Set<String> choice : incompleteChoices) { Set<String> newChoice = new HashSet<>(choice); newChoice.add(variable); if (newChoice.size() == n) { completeChoices.add(newChoice); } else { newChoices.add(newChoice); } } for (Set<String> choice : newChoices) { incompleteChoices.add(choice); } } //for each choice of n negative variables, make the needed variable assignments for (Set<String> choice : completeChoices) { List<Map<String, String>> product = new LinkedList<>(productCore); Set<String> newlyNegativeVariables = new HashSet<>(hasNegativeVariables); //make the negative assignments for (String variable : choice) { NegativeAssign neg = negativeAssignments.get(variable); String expr = neg.getExpr(); product = takeProduct(product, variable, splitSet(expr)); newlyNegativeVariables.add(variable); } //make all other potentially negative assignments positive for (String variable2 : negativeAssignments.keySet()) { if (!choice.contains(variable2)) { Assign assign = positiveAssignments.get(variable2); String expr = assign.getExpr(); product = takeProduct(product, variable2, splitSet(expr)); } } //apply every transform tag to the results of the cartesian product for (Action action : actions) { if (action instanceof Transform) { String name = ((Transform) action).getName(); DataTransformer tr = transformations.get(name); DataPipe pipe = new DataPipe(0, null); for (Map<String, String> p : product) { pipe.getDataMap().putAll(p); tr.transform(pipe); p.putAll(pipe.getDataMap()); } } } checkTransitions(nextState, product, newlyNegativeVariables, bootStrap); } } }
From source file:org.finra.datagenerator.engine.scxml.tags.SingleValueAssignExtension.java
/** * Assigns one variable to one value/*w w w .j a v a 2 s . c o m*/ * * @param action an Assign Action * @param possibleStateList a current list of possible states produced so far from expanding a model state * * @return the same list, with every possible state augmented with an assigned variable, defined by action */ public List<Map<String, String>> pipelinePossibleStates(Assign action, List<Map<String, String>> possibleStateList) { for (Map<String, String> possibleState : possibleStateList) { possibleState.put(action.getName(), action.getExpr()); } return possibleStateList; }