MCPcopy Create free account
hub / github.com/5zig/The-5zig-Mod / init

Method init

The 5zig Mod/src/eu/the5zig/mod/chat/NetworkStats.java:47–74  ·  view source on GitHub ↗
(Database sql)

Source from the content-addressed store, hash-verified

45 }
46
47 public void init(Database sql) {
48 this.sql = sql;
49
50 sql.update("CREATE TABLE IF NOT EXISTS network_stats (key VARCHAR(20), value VARCHAR(20))");
51
52 List<NetworkStatsEntity> entityBaseList = sql.get(NetworkStatsEntity.class).query("SELECT * FROM network_stats").getAll();
53 if (entityBaseList.isEmpty()) {
54 sql.update("INSERT INTO network_stats (key, value) VALUES ('packetsSent', '0'), ('packetsReceived', '0'), ('bytesSent', '0'), ('bytesReceived', '0'), ('since', ?)",
55 System.currentTimeMillis());
56 since = System.currentTimeMillis();
57 } else {
58 for (NetworkStatsEntity entity : entityBaseList) {
59 String key = entity.getKey();
60 String value = entity.getValue();
61
62 if (key.equals("packetsSent"))
63 totalPacketsSent = Integer.parseInt(value);
64 if (key.equals("packetsReceived"))
65 totalPacketsReceived = Integer.parseInt(value);
66 if (key.equals("bytesSent"))
67 totalBytesSent = Long.parseLong(value);
68 if (key.equals("bytesReceived"))
69 totalBytesReceived = Long.parseLong(value);
70 if (key.equals("since"))
71 since = Long.parseLong(value);
72 }
73 }
74 }
75
76 public void tick() {
77 if (System.currentTimeMillis() - lastSaveTime > 1000 * 60) {

Callers

nothing calls this directly

Calls 10

getAllMethod · 0.80
isEmptyMethod · 0.80
parseLongMethod · 0.80
getMethod · 0.65
updateMethod · 0.45
queryMethod · 0.45
getKeyMethod · 0.45
getValueMethod · 0.45
equalsMethod · 0.45
parseIntMethod · 0.45

Tested by

no test coverage detected