[英]How to generate multiple Tuples or String combinations of a custom Java Object
I'm trying to run a program that would load test my backend application. 我正在尝试运行将对后端应用程序进行负载测试的程序。 The program should generate all combinations of tuples of a particular class given the cardinality of each attribute of the class. 给定该类每个属性的基数,该程序应生成特定类的所有元组组合。
For example consider this class 例如考虑这个班
public ClassA{
String name;
String id;
String kind;
}
The use case is that the user will input cardinality of each attribute of this class and the output should List of Strings/Tuples of those values. 用例是用户将输入此类的每个属性的基数,并且输出应为这些值的字符串/字符串列表。 For eg: User inputs name
with cardinality 100
, kind
with cardinality 10
and id
with cardinality 1000
. 为例如:用户输入name
与基数100
, kind
用基数10
和id
与基数1000
。 Basically range of attributes generated will be name_0
to name_99
, kind_0
to kind_9
, id_0
to id_999
. 基本上,生成的属性范围是name_0
到name_99
, kind_0
到kind_9
, id_0
到id_999
。 So there will be a total of 1000*10*100
combinations. 这样一共有1000*10*100
组合。
This should generate 这应该产生
< name_0, id_0, kind_0>
< name_0, id_0, kind_1>
< name_0, id_0, kind_2>
.
.
.
.
< name_0, id_1, kind_0>
< name_0, id_2, kind_0>
< name_0, id_3, kind_0>
.
.
.
.
< name_1, id_0, kind_0>
< name_2, id_0, kind_0>
< name_3, id_0, kind_0>
.
.
.
.
What is the best way to do this? 做这个的最好方式是什么? From both an implementation and design perspective ? 从实现和设计的角度来看? Any examples would definitely help 任何例子肯定会有所帮助
Something like the following: 类似于以下内容:
IntStream.range(0, nameCount)
.flatMap(n -> IntStream.range(0, idCount)
.flatMap(i -> IntStream.range(0, kindCount)
.map(k -> new ClassA("name_" + n, "id_" + i, "kind_" + k))))
.collect(Collectors.toList());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.