Starsector API
Loading...
Searching...
No Matches
PLSnapshot.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.plog;
2
3import java.util.HashMap;
4import java.util.Map;
5
6import com.fs.starfarer.api.Global;
7
8public class PLSnapshot {
9
10 protected Map<String, Long> data = new HashMap<String, Long>();
11 protected long timestamp = 0;
12
13 public PLSnapshot(String in) {
14 setFromString(in);
15 }
16
17 public PLSnapshot() {
18 timestamp = Global.getSector().getClock().getTimestamp();
19 }
20
21 public long getTimestamp() {
22 return timestamp;
23 }
24
25 public void setTimestamp(long timestamp) {
26 this.timestamp = timestamp;
27 }
28
29 public Map<String, Long> getData() {
30 return data;
31 }
32
33 public void setFromString(String in) {
34 String [] parts = in.split("\\|");
35
36 data = new HashMap<String, Long>();
37
38 boolean first = true;
39 for (String p : parts) {
40 if (first) {
41 timestamp = Long.parseLong(p);
42 first = false;
43 continue;
44 }
45 String [] p2 = p.split(":");
46 String key = p2[0];
47 long value = Long.parseLong(p2[1]);
48 data.put(key, value);
49 }
50 }
51
52 public String getString() {
53 String str = "";
54
55 str += timestamp + "|";
56
57 for (String key : data.keySet()) {
58 str += key + ":" + data.get(key) + "|";
59 }
60 if (!str.isEmpty()) {
61 str = str.substring(0, str.length() - 1);
62 }
63 return str;
64 }
65
66
67}
static SectorAPI getSector()
Definition Global.java:59