|
|
Re: the order of the element in the collection does not maintain [message #1067234 is a reply to message #1067231] |
Sun, 07 July 2013 19:47 |
ibrahim kara Messages: 10 Registered: May 2012 |
Junior Member |
|
|
Hi there,
Here is the for loop I call the Java service:
[template public transitionCode(aState : State, args0 : OclAny, args1 : OclAny) post(trim())]
[for (aTransition : Transition | outgoing->filter(Transition)->asSequence()->oclAsSet().filterJoinTargetsOut()->filter(Transition)->asSequence()->oclAsSet().sortTransitions()->asSequence()->first())]
if [if (source.container.qualifiedName = target.container.qualifiedName)]
[if (source.eClass().name = 'State' and (target.eClass().name = 'State' or target.eClass().name = 'FinalState'))]
[simpleTransitionCode(args0)/]
[else]
[pseudostateTargetTransitionCode(args0, args1->filter(State))/]
[/if]
[else]
<%-- /*start interlevel transition <%args(0)%>*/ --%>[/comment]
[if (source.eClass().name = 'State' and (target.eClass().name = 'State' or target.eClass().name = 'FinalState'))]
[interLevelTransition(args0)/]
[else]
[pseudostateTargetTransitionCode(args0, args1->filter(State))/]
[/if]
/*end interlevel transition*/
[/if]
[/for]
......
[/template]
Here is the Java code:
public LinkedList<Transition> sortTransitions(List<Transition> list)
//throws ENodeCastException, ClassCastException
{
//EList<Transition> list = aVertex.getIncomings();
//EList<Transition> filterJoinTargetsOut = (EList<Transition>)filterJoinTargetsOut((State)aVertex);
//EList<Transition> list = filterJoinTargetsOut;
//EList<Transition> list = aVertex.getOutgoings();
//EList<Transition> list = new BasicEList<Transition>();
//if(listobject instanceof EList)
//list = (EList<Transition>) listobject;
Set<Transition> unpriorizedSet = new LinkedHashSet<Transition>();
TreeMap<Integer, Transition> tm = new TreeMap<Integer, Transition>(
new TransitionComparator());
UmlServices umlservice = new UmlServices();
LinkedList<Transition> sortedList = new LinkedList<Transition>();
Set<Entry<Integer, Transition>> set = null;
// if list is empty return empty list
if (list == null || list.size() == 0) {
return sortedList;
}
for (Iterator<Transition> iterator = list.iterator(); iterator.hasNext() {// Iterator<.......> FIX
Transition transition = (Transition) iterator.next();
Stereotype stereotype = umlservice.getStereotype(transition,
"ExecutionOrderPriority");
if (stereotype == null) {
unpriorizedSet.add(transition);
} else {
Integer transitionPriority = (Integer) transition.getValue(
stereotype, "priority");
if (transitionPriority != null) {
if (!tm.containsKey(transitionPriority)) {
tm.put(transitionPriority, transition);
} else {
unpriorizedSet.add(transition);
}
} else {
unpriorizedSet.add(transition);
}
}
// }
}
set = tm.entrySet();
for (Entry<Integer, Transition> entry : set) {
sortedList.add(entry.getValue());
}
for (Transition entry : unpriorizedSet) {
sortedList.add(entry);
}
/* TO TEST THE SORTING
int base=0;
for (Iterator<Transition> iterator = sortedList.iterator(); iterator.hasNext() {
Transition transition = (Transition) iterator.next();
Stereotype stereotype = umlservice.getStereotype(transition,
"ExecutionOrderPriority");
if((Integer) transition.getValue(stereotype, "priority") > base){
}
else{ return null;}
base= (Integer)transition.getValue(stereotype, "priority");
}
*/
return sortedList;
}
and here is the Java service wrapper:
[query public sortTransitions(arg0 : Sequence(Transition)) : OrderedSet(Transition)
= invoke('org.openmodelica.modelicaml.generate.modelica.services.ModelicaMLServices', 'sortTransitions(java.util.List)', Sequence{arg0}) /]
The java code does sort the transitions according to their priorities but when the list is returned to the for loop it has different order every run.
Thanks for the help.
|
|
|
|
Re: the order of the element in the collection does not maintain [message #1067249 is a reply to message #1067234] |
Mon, 08 July 2013 05:52 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
Hi
You only provide an uncheckable snippet of your code so it's still
difficult to give you a proper answer however, each time you call
->oclAsSet() you allow the tooling to create a random ordering in
excahnge for uniqueness.
Regards
Ed Willink
On 07/07/2013 20:47, ibrahim kara wrote:
> Hi there,
>
> Here is the for loop I call the Java service:
> [template public transitionCode(aState : State, args0 : OclAny, args1
> : OclAny) post(trim())]
> [for (aTransition : Transition |
> outgoing->filter(Transition)->asSequence()->oclAsSet().filterJoinTargetsOut()->filter(Transition)->asSequence()->oclAsSet().sortTransitions()->asSequence()->first())]
> if [if (source.container.qualifiedName =
> target.container.qualifiedName)]
> [if (source.eClass().name = 'State' and (target.eClass().name
> = 'State' or target.eClass().name = 'FinalState'))]
> [simpleTransitionCode(args0)/]
> [else]
> [pseudostateTargetTransitionCode(args0, args1->filter(State))/]
> [/if]
> [else]
> <%-- /*start interlevel transition <%args(0)%>*/ --%>[/comment]
> [if (source.eClass().name = 'State' and (target.eClass().name
> = 'State' or target.eClass().name = 'FinalState'))]
> [interLevelTransition(args0)/]
> [else]
> [pseudostateTargetTransitionCode(args0, args1->filter(State))/]
> [/if]
> /*end interlevel transition*/
> [/if]
> [/for]
> .....
> [/template]
>
> Here is the Java code:
> public LinkedList<Transition> sortTransitions(List<Transition> list)
> //throws ENodeCastException, ClassCastException {
> //EList<Transition> list = aVertex.getIncomings();
> //EList<Transition> filterJoinTargetsOut =
> (EList<Transition>)filterJoinTargetsOut((State)aVertex);
> //EList<Transition> list = filterJoinTargetsOut;
> //EList<Transition> list = aVertex.getOutgoings();
>
> //EList<Transition> list = new BasicEList<Transition>();
> //if(listobject instanceof EList)
> //list = (EList<Transition>) listobject;
> Set<Transition> unpriorizedSet = new LinkedHashSet<Transition>();
> TreeMap<Integer, Transition> tm = new TreeMap<Integer,
> Transition>(
> new TransitionComparator());
>
> UmlServices umlservice = new UmlServices();
> LinkedList<Transition> sortedList = new LinkedList<Transition>();
> Set<Entry<Integer, Transition>> set = null;
> // if list is empty return empty list
> if (list == null || list.size() == 0) {
> return sortedList;
> }
> for (Iterator<Transition> iterator = list.iterator();
> iterator.hasNext();) {// Iterator<.......> FIX
> Transition transition = (Transition) iterator.next();
> Stereotype stereotype = umlservice.getStereotype(transition,
> "ExecutionOrderPriority");
>
> if (stereotype == null) {
> unpriorizedSet.add(transition);
> } else {
> Integer transitionPriority = (Integer)
> transition.getValue(
> stereotype, "priority");
> if (transitionPriority != null) {
> if (!tm.containsKey(transitionPriority)) {
> tm.put(transitionPriority, transition);
> } else {
> unpriorizedSet.add(transition);
> }
> } else {
> unpriorizedSet.add(transition);
> }
> }
>
> // }
> }
>
> set = tm.entrySet();
> for (Entry<Integer, Transition> entry : set) {
> sortedList.add(entry.getValue());
> }
> for (Transition entry : unpriorizedSet) {
> sortedList.add(entry);
> }
>
> /* TO TEST THE SORTING
> int base=0;
> for (Iterator<Transition> iterator = sortedList.iterator();
> iterator.hasNext();) {
> Transition transition = (Transition) iterator.next();
> Stereotype stereotype = umlservice.getStereotype(transition,
> "ExecutionOrderPriority");
> if((Integer) transition.getValue(stereotype, "priority") >
> base){
> }
> else{ return null;}
> base= (Integer)transition.getValue(stereotype, "priority");
> }
> */
>
> return sortedList;
> }
>
> and here is the Java service wrapper:
>
> [query public sortTransitions(arg0 : Sequence(Transition)) :
> OrderedSet(Transition)
> =
> invoke('org.openmodelica.modelicaml.generate.modelica.services.ModelicaMLServices',
> 'sortTransitions(java.util.List)', Sequence{arg0}) /]
>
>
> The java code does sort the transitions according to their priorities
> but when the list is returned to the for loop it has different order
> every run.
> Thanks for the help.
>
>
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03241 seconds