001package com.fs.starfarer.api.impl.campaign.plog; 002 003import java.util.HashMap; 004import java.util.Map; 005 006import com.fs.starfarer.api.Global; 007 008public class PLSnapshot { 009 010 protected Map<String, Long> data = new HashMap<String, Long>(); 011 protected long timestamp = 0; 012 013 public PLSnapshot(String in) { 014 setFromString(in); 015 } 016 017 public PLSnapshot() { 018 timestamp = Global.getSector().getClock().getTimestamp(); 019 } 020 021 public long getTimestamp() { 022 return timestamp; 023 } 024 025 public void setTimestamp(long timestamp) { 026 this.timestamp = timestamp; 027 } 028 029 public Map<String, Long> getData() { 030 return data; 031 } 032 033 public void setFromString(String in) { 034 String [] parts = in.split("\\|"); 035 036 data = new HashMap<String, Long>(); 037 038 boolean first = true; 039 for (String p : parts) { 040 if (first) { 041 timestamp = Long.parseLong(p); 042 first = false; 043 continue; 044 } 045 String [] p2 = p.split(":"); 046 String key = p2[0]; 047 long value = Long.parseLong(p2[1]); 048 data.put(key, value); 049 } 050 } 051 052 public String getString() { 053 String str = ""; 054 055 str += timestamp + "|"; 056 057 for (String key : data.keySet()) { 058 str += key + ":" + data.get(key) + "|"; 059 } 060 if (!str.isEmpty()) { 061 str = str.substring(0, str.length() - 1); 062 } 063 return str; 064 } 065 066 067}