1
mirror of https://github.com/CarmJos/UltraDepository.git synced 2026-06-04 16:48:21 +08:00

[v1.1.2] 采用Map的形式序列化用户数据。

This commit is contained in:
2021-12-30 20:38:58 +08:00
parent bfbf55c9fc
commit 92b9c45911
5 changed files with 113 additions and 41 deletions
+41
View File
@@ -0,0 +1,41 @@
import com.google.gson.Gson;
import org.junit.Test;
import java.util.*;
public class GsonMapTest {
private static final Gson GSON = new Gson();
@Test
public void test() {
Map<String, Map<String, Map<String, Integer>>> values = new LinkedHashMap<>();
for (int u = 0; u < 3; u++) {
Map<String, Map<String, Integer>> depositoryDataMap = new LinkedHashMap<>();
for (int i = 0; i < 5; i++) {
Map<String, Integer> itemDataMap = new HashMap<>();
int amount = Math.max(0, new Random().nextInt(15));
int sold = Math.max(0, new Random().nextInt(15));
if (amount > 0) itemDataMap.put("amount", amount);
if (sold > 0) itemDataMap.put("sold", sold);
if (!itemDataMap.isEmpty()) {
depositoryDataMap.put(UUID.randomUUID().toString().substring(0, 4), itemDataMap);
}
}
if (!depositoryDataMap.isEmpty()) {
values.put(UUID.randomUUID().toString().substring(0, 8), depositoryDataMap);
}
}
System.out.println(values.size());
String jsonValues = GSON.toJson(values);
System.out.println(jsonValues);
}
}