【发布时间】:2013-12-07 19:00:58
【问题描述】:
对于给定的Collection<Object> aCollection,我如何构建一个ArrayList<OrderedCouple<Object>>,其中包含aCollection 中所有可能的组合排列(自耦合除外)。
例如,假设aCollection 是一个包含teamA、teamB 和teamC 的Set<Team>,而OrderedCouple 是一个类Game<Team>,它的构造函数接收两个团队,主机和客人作为论据。
我想在Teams 之间构建所有可能的Games 的ArrayList。也就是说,ArrayList 将是组{new Game(teamA, teamB), new Game(teamA, teamC), new Game(teamB, teamA), new Game(teamB, teamC), new Game(teamC, teamA), new Game(teamC, teamB)} 的随机顺序。
【问题讨论】:
-
从 itertools.permutations 导入...哦等等这是 java :((为什么标准 API 不能有这些东西。
-
我认为 Guava 库可以帮助您使用 Collections2 轻松获得一些东西。 docs.guava-libraries.googlecode.com/git/javadoc/com/google/…
标签: java random arraylist coupling