use of org.iobserve.analysis.behavior.karlsruhe.data.ISequenceElement in project iobserve-analysis by research-iobserve.
the class BranchModelCreator method mergeBranches.
/**
* Merges branches.
*
* @param branch
* whose child branches are merged
* @param doChildBranchesExist
* @return
*/
private boolean mergeBranches(final Branch branch, final boolean doChildBranchesExist) {
int indexOfEqualElements = 0;
boolean isElementEqual = false;
// their sequences
for (int i = branch.getChildBranches().get(0).getBranchSequence().size() - 1; i >= 0; i--) {
final ISequenceElement branchElement = branch.getChildBranches().get(0).getBranchSequence().get(i);
isElementEqual = false;
for (final Branch childBranch : branch.getChildBranches()) {
if (childBranch.getBranchSequence().size() - 1 - indexOfEqualElements < 0) {
isElementEqual = false;
break;
} else if (this.doBranchElementsMatch(branchElement, childBranch.getBranchSequence().get(childBranch.getBranchSequence().size() - 1 - indexOfEqualElements))) {
isElementEqual = true;
} else {
isElementEqual = false;
break;
}
}
if (!isElementEqual) {
break;
}
indexOfEqualElements++;
}
// Creates a new branch element that replaces the child branches that are merged
final BranchElement branchElement = new BranchElement();
final List<ISequenceElement> sequenceToAddToBranch = new ArrayList<>();
for (int i = 0; i < indexOfEqualElements; i++) {
sequenceToAddToBranch.add(0, branch.getChildBranches().get(0).getBranchSequence().get(branch.getChildBranches().get(0).getBranchSequence().size() - 1));
for (final Branch childBranch : branch.getChildBranches()) {
childBranch.getBranchSequence().remove(childBranch.getBranchSequence().size() - 1);
}
}
for (final Branch childBranch : branch.getChildBranches()) {
final BranchTransitionElement branchTransition = new BranchTransitionElement();
branchTransition.setBranchSequence(childBranch.getBranchSequence());
branchTransition.setTransitionLikelihood(childBranch.getBranchLikelihood());
branchElement.addBranchTransition(branchTransition);
}
branch.getBranchSequence().add(branchElement);
branch.getBranchSequence().addAll(sequenceToAddToBranch);
// Removes the replaced child branches
if (doChildBranchesExist) {
final List<Branch> newChildBranches = branch.getChildBranches().get(0).getChildBranches();
branch.getChildBranches().clear();
branch.setChildBranches(newChildBranches);
} else {
branch.getChildBranches().clear();
}
if (doChildBranchesExist || indexOfEqualElements > 0) {
this.fusionPerformed = true;
return true;
} else {
return false;
}
}
use of org.iobserve.analysis.behavior.karlsruhe.data.ISequenceElement in project iobserve-analysis by research-iobserve.
the class BranchModelCreator method setBranchSequence.
/**
* Sets the passed events as branch sequence of the passed branch. The sequenceStartIndex
* defines at which position of the passed events the branch sequence starts
*
* @param examinedBranch
* for that the branchSequence will be set
* @param events
* represent the sequence to set
* @param sequenceStartIndex
* states at which position of the passed events the branch sequence starts
*/
private void setBranchSequence(final Branch examinedBranch, final List<EntryCallEvent> events, final int sequenceStartIndex) {
final List<ISequenceElement> branchSequence = new ArrayList<>();
for (int j = sequenceStartIndex; j < events.size(); j++) {
final EntryCallEvent callEvent = events.get(j);
final CallElement callElement = new CallElement(callEvent.getClassSignature(), callEvent.getOperationSignature());
callElement.setAbsoluteCount(1);
branchSequence.add(callElement);
}
final ExitElement exitElement = new ExitElement();
exitElement.setAbsoluteCount(1);
branchSequence.add(exitElement);
examinedBranch.setBranchSequence(branchSequence);
}
Aggregations