Skip to content

Commit 913341a

Browse files
committed
Update constructors in ASTFAssociationRule
1 parent 0569f9a commit 913341a

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/main/java/com/cisco/trex/stateful/api/lowlevel/ASTFAssociationRule.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.cisco.trex.stateful.api.lowlevel;
22

3+
import com.google.gson.JsonArray;
34
import com.google.gson.JsonObject;
45
import java.util.List;
56
import java.util.Map;
@@ -43,9 +44,11 @@ public ASTFAssociationRule(int port) {
4344
* @param l7List
4445
*/
4546
public ASTFAssociationRule(String ipStart, String ipEnd, int port, List<Integer> l7List) {
46-
this(null, null, port);
47+
this(ipStart, ipEnd, port);
4748
if (!l7List.isEmpty()) {
48-
fields.addProperty("l7_map", "{\"offset\": " + l7List.toString() + "}");
49+
JsonObject l7_map = new JsonObject();
50+
addL7MapProperty(l7List, l7_map, "offset");
51+
fields.add("l7_map", l7_map);
4952
}
5053
}
5154

@@ -59,14 +62,22 @@ public ASTFAssociationRule(String ipStart, String ipEnd, int port, List<Integer>
5962
*/
6063
public ASTFAssociationRule(
6164
String ipStart, String ipEnd, int port, Map<String, List<Integer>> l7Map) {
62-
this(null, null, port);
65+
this(ipStart, ipEnd, port);
6366
if (!l7Map.isEmpty()) {
64-
String l7_map =
65-
String.format(
66-
"{\"offset\": %s, \"value\": %s}",
67-
l7Map.get("offset").toString(), l7Map.get("value").toString());
68-
fields.addProperty("l7_map", l7_map);
67+
JsonObject l7_map = new JsonObject();
68+
addL7MapProperty(l7Map.get("offset"), l7_map, "offset");
69+
addL7MapProperty(l7Map.get("value"), l7_map, "value");
70+
fields.add("l7_map", l7_map);
71+
}
72+
}
73+
74+
private void addL7MapProperty(List<Integer> values, JsonObject l7Map, String property) {
75+
if (values == null || values.isEmpty()) {
76+
return;
6977
}
78+
JsonArray jsonArray = new JsonArray();
79+
values.forEach(jsonArray::add);
80+
l7Map.add(property, jsonArray);
7081
}
7182

7283
/**

0 commit comments

Comments
 (0)