Hi Thierry,The input String is naturally ordered, that's a given. However, depending on the signature of your "splitNewLine()" service, it may very well be unordered as a result of the call : if "splitNewLine" is defined to return a "Set" or a "Bag", then whatever you do, the result will be unordered. For "Set", OCL uses an HashSet internally. For "Bag", OCL uses a custom implementation of a MultiSet backed by an HashSet. Whatever the case, these two order their content according to each value's hash code, which you shouldn't expect to be constant accross different invocations/VMs/machines/...
In order to enforce a constant iteration order, you will have to either * specify "splitNewLine" to return an ordered collection. If it is defined in Java, ensure it return type is either "List" or "LinkedHashSet". If it is defined in OCL, ensure its return type is either "Sequence" or "OrderedSet". * cast its result as an ordered collection (I am not sure this will be sufficient). Simply add "->asSequence()" or "->asOrderedSet()" after your calls to "splitNewLine". * manually reorder the result... though it might be difficult to order your lines according to their position in the input String. This is done through "->sortedBy(expression)". Regards, Laurent Goubet Obeo On 03/12/2013 15:08, Topcased user list where issues are discussed wrote:
Hi Laurent,Thanks for the links but I think my problem is not directly related to these because "my" input is a String, so all the '\n'-separated substrings are naturally ordered (they should be).I face the same problem when I use tokenizeLine()... Regards, Thierry. Topcased user list where issues are discussed a écrit :Hi,I don't know the splitNewLine() service. But perhaps, splitNewLine() returns a non ordered list? Some related links to random order problem with Accelo3 that may be able to help you:* http://www.eclipse.org/forums/index.php/t/236582/ * http://www.eclipse.org/forums/index.php/t/167358/ Regards, LaurentLe 03/12/2013 11:20, Topcased user list where issues are discussed a écrit :Hi Topcased users,I use the latest version of Accelo under Topcased 5.1, and I wrote an acceleo script which uses splitNewLine(). This function seems to work correctly except that the lines provided are not in the initial order.Example : I want to display the comment associated with a Constraint of an Operation. I use this code :[comment] c : Constraint => c.ownedComment._body is of type String [/comment][for (line : String | c.ownedComment._body.splitNewLine())] [line/] [/for]If c.ownedComment._body would be "line1\nline2\nline3", then the code above would give :line3 line2 line1 or line1 line3 line2I can't figure out the order of the display, but, very often, it is not the order of the initial string.Any clue ? (I also use, with success, xx.getDocumentation().splitNewLine() on )Regards, Thierry. _______________________________________________ Topcased-users mailing list [email protected] http://lists.gforge.enseeiht.fr/cgi-bin/mailman/listinfo/topcased-users------------------------------------------------------------------------ _______________________________________________ Topcased-users mailing list [email protected] http://lists.gforge.enseeiht.fr/cgi-bin/mailman/listinfo/topcased-users_______________________________________________ Topcased-users mailing list [email protected] http://lists.gforge.enseeiht.fr/cgi-bin/mailman/listinfo/topcased-users
<<attachment: laurent_goubet.vcf>>
_______________________________________________ Topcased-users mailing list [email protected] http://lists.gforge.enseeiht.fr/cgi-bin/mailman/listinfo/topcased-users
