扩展循环中断

Cha*_*nry 5 loops code-generation break xtend

在 Xtend 中,是否可以中断循环或检查以中断循环?

\n\n
\xc2\xabFOR e:d.entitys\xc2\xbb\n    \xc2\xabFOR a:e.attributes\xc2\xbb\n        \xc2\xabIF a.eClass.name.contentEquals(\'Something\')\xc2\xbb\n            \xc2\xabe.name\xc2\xbb "This output should be output one for each Entity e"\n        \xc2\xabENDIF\xc2\xbb\n    \xc2\xabENDFOR\xc2\xbb\n\xc2\xabENDFOR\xc2\xbb\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的输出是:

\n\n
Entity 1 "This output should be output one for each Entity e"\nEntity 1 "This output should be output one for each Entity e"\nEntity 1 "This output should be output one for each Entity e"\nEntity 2 "This output should be output one for each Entity e"\nEntity 4 "This output should be output one for each Entity e"\nEntity 4 "This output should be output one for each Entity e"\n
Run Code Online (Sandbox Code Playgroud)\n\n

但我想要的是:

\n\n
Entity 1 "This output should be output one for each Entity e"\nEntity 2 "This output should be output one for each Entity e"\nEntity 4 "This output should be output one for each Entity e"\n
Run Code Online (Sandbox Code Playgroud)\n\n

如何实现我想要的输出?我听说你可以调用另一种方法或其他方法,但我不知道该怎么做,有人可以给我看一些解决这个问题的代码吗?\n谢谢:)

\n

Dan*_*ini 0

您可以使用一个集合来存储您已经访问过的条目。例如,考虑以下程序:

\n\n
def static void main(String... args) {\n    val list = #[\'my\', \'possibly\', \'possibly\', \'duplicated\', \'duplicated\', \'duplicated\', \'entities\']\n    val visited = new LinkedHashSet\n    println(\n    \'\'\'\xc2\xabFOR a:list\xc2\xbb\n        \xc2\xabIF visited.add(a)\xc2\xbb\n            \xc2\xaba\xc2\xbb "This output should be output one for each Entity e"\n        \xc2\xabENDIF\xc2\xbb\n    \xc2\xabENDFOR\xc2\xbb\'\'\')\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

它输出:

\n\n
my "This output should be output one for each Entity e"\npossibly "This output should be output one for each Entity e"\nduplicated "This output should be output one for each Entity e"\nentities "This output should be output one for each Entity e"\n
Run Code Online (Sandbox Code Playgroud)\n