Basically, I'd like to depict the below logic in a Sequence Diagram:
if (ShopIsOpen) {
if (AccessTokenIsExpired) {
if (RefreshTokenInExpired) {
return "Not Authorized";
}
IdentityServer.RequestAccessTokenByRefreshToken();
return Resource.RequestResourceByAccessToken();
}
} else {
return "Shop is closed";
}
I've come up with the below diagram, but I am not sure if it is correct.
Mainly, I am not sure if break in the diagram correctly communicates the intention of termination of flow: does it imply jumping out of the outer opt or the outer alt?
Any help is much appreciated.
The break fragment leaves the immediately enclosing fragment. In your case that would be the opt fragment. So, it is not correct. Why don’t you use nested alt fragments?
Some additional remarks: The reply to a synchronous message is shown with a dashed line and the returned value is shown with a leading colon (and the name of the original message, but I think it is obvious here anyway).
I wonder how they achieved || functionality with (&& and unlikely) in the below piece of code.
if (unlikely(!arch_get_random_seed_long(&v)) && unlikely(!arch_get_random_long(&v))) {
break;
}
As per design, if arch_get_random_seed_long gets value &v there is no need to fill the value again in arch_get_random_long(). This piece of code working fine.
But, how do 'unlikely' achieve this. Skipping the remaining code after && once [unlikely(!0)] is achieved.
Thanks,
Paavaanan
I'm building an application which uses jointjs / rappid and I want to be able to avoid loops from occuring across multiple cells.
Jointjs already has some examples on how to avoid this in a single cell (connecting an "out" port to an "in" port of the same cell) but has nothing on how to detect and prevent loops from occuring further up in the chain.
To help understand, imagine each cell in the paper is a step to be completed. Each step should only ever be run once. If the last step has an "out" port that connects to the "in" port of the first cell, it will just loop forever. This is what I want to avoid.
Any help is greatly appreciated.
I actually found a really easy way to do this for anyone else who wishes to achieve the same thing. Simply include the graphlib dependancy and use the following:
paper.on("link:connect", function(linkView) {
if(graphlib.alg.findCycles(graph.toGraphLib()).length > 0) {
linkView.model.remove();
// show some error message here
}
});
This line:
graphlib.alg.findCycles(graph.toGraphLib())
Returns an array that contains any loops, so by checking the length we can determine whether or not the paper contains any loops and if so, remove the link that the user is trying to create.
Note: This isn't completely full-proof because if the paper already contains a loop (before the user adds a link) then simply removing the link that the user is creating won't remove any loop that exists. For me this is fine because all of my papers will be created from scratch so as long as this logic is always in place, no loops can ever be created.
Solution through graphlib
Based on Adam's graphlib solution, instead of findCycles to test for loops, the graphlib docs suggests to use the isAcyclic function, which:
returns true if the graph has no cycles and returns false if it does. This algorithm returns as soon as it detects the first cycle.
Therefore this condition:
if(graphlib.alg.findCycles(graph.toGraphLib()).length > 0)
Can be shortened to:
if(!graphlib.alg.isAcyclic(graph))
JointJS functions solution
Look up the arrays of ancestors and successors of a newly connected element and intersect them:
// invoke inside an event which tests if a specific `connectedElement` is part of a loop
function isElementPartOfLoop (graph, connectedElement) {
var elemSuccessors = graph.getSuccessors(connectedElement, {deep: true});
var elemAncestors = connectedElement.getAncestors();
// *** OR *** graph.getPredecessors(connectedElement, {deep: true});
var commonElements = _.intersection(elemSuccessors, elemAncestors);
// if an element is repeated (non-empty intersection), then it's part of a loop
return !_.isEmpty(commonElements);
}
I haven't tested this, but the theory behind the test you are trying to accomplish should be similar.
This solution is not as efficient as using directly the graphlib functions.
Prevention
One way you could prevent the link from being added to the graph is by dealing with it in an event:
graph.on('add', _.bind(addCellOps, graph));
function addCellOps (cell, collection, opt) {
if (cell.isLink()){
// test link's target element: if it is part of a loop, remove the link
var linkTarget = cell.getTargetElement();
// `this` is the graph
if(target && isElementPartOfLoop(this, linkTarget)){
cell.remove();
}
}
// other operations ....
}
Since Antlr4 no longer supports gated semantic predicates, I came up with a workaround. However, if anyone has run into this, I would like to know if there are any caveats to doing something like this and also am I following best practices.
I'm following the standard 'C' if statement in the form of:
if (evaluation) {
...code block
}
Here is the code in the code block:
if ($result == false) { // If the statement evealuates to false
// Consume tokens until the end of block marker
while (getCurrentToken().getText().compareTo("}") != 0){
consume();
}
// Set the parser state as if it had executed the tokens
_localctx.start = getCurrentToken();
_ctx.start = getCurrentToken();
setState(220);
_errHandler.sync(this);
consume(); // Consume the end of block marker
return _localctx; // Exit the rule
}
I figure that Terrance Parr must have had a good reason to take out the support for a gated semantic predicate and this seems like a simple workaround. I'm just wondering if I'm missing something.
I tested it and it works, even with an 'else'. I have not tried it with compound evaluation statements (ie conditions separated with '&&' or '||'. I have a high confidence that it will work though.
I want to create a sequence diagram of my program.
The code goes like this:
I have a class SFC, this class starts with the method parseScenario(). The parseScenario() method is a loop until all elements in a list are looped over. In this loop I call the parseEntryLine(e) method, where e is an entry in that list.
Now my problem occurs.
In parseEntryLine(e) there is an IF statement as follows:
if (currentGM.isBrick ()) {
animateExpr(currentGM);
//Check if it has a next
if (currentGM._next != null) { parseEntryLine (currentGM._next); }
} else {
//random code
parseEntryLine(buttonStringClicked);
}
}
How do I model this in a sequence diagram?
I managed to work until this point:
(I realize this might already be a wrong start).