From 7f31e7edb96094c2e5652c43ed7da0dedb598804 Mon Sep 17 00:00:00 2001 From: Victor Date: Thu, 23 Apr 2015 14:13:56 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20SaveInfo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../annimon/everlastingsummer/SaveInfo.java | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 src/com/annimon/everlastingsummer/SaveInfo.java diff --git a/src/com/annimon/everlastingsummer/SaveInfo.java b/src/com/annimon/everlastingsummer/SaveInfo.java new file mode 100644 index 0000000..45e8efc --- /dev/null +++ b/src/com/annimon/everlastingsummer/SaveInfo.java @@ -0,0 +1,128 @@ +package com.annimon.everlastingsummer; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import android.os.Parcel; +import android.os.Parcelable; + +/** + * Информация о сохранении. + * @author aNNiMON + */ +public final class SaveInfo implements Parcelable { + + private String path; + private long time; + private int position; + private Map variables; + + public SaveInfo() {} + + public SaveInfo(String path, long time, int position, Map variables) { + this.path = path; + this.time = time; + this.position = position; + this.variables = variables; + } + + private SaveInfo(Parcel in) { + path = in.readString(); + time = in.readLong(); + position = in.readInt(); + final int varSize = in.readInt(); + variables = new HashMap(varSize); + for (int i = 0; i < varSize; i++) { + variables.put(in.readString(), in.readDouble()); + } + } + + private SaveInfo(DataInputStream in) throws IOException { + path = in.readUTF(); + time = in.readLong(); + position = in.readInt(); + final int varSize = in.readInt(); + variables = new HashMap(varSize); + for (int i = 0; i < varSize; i++) { + variables.put(in.readUTF(), in.readDouble()); + } + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public long getTime() { + return time; + } + + public void setTime(long time) { + this.time = time; + } + + public int getPosition() { + return position; + } + + public void setPosition(int position) { + this.position = position; + } + + public Map getVariables() { + return variables; + } + + public void setVariables(Map variables) { + this.variables = variables; + } + + public static SaveInfo readFromStream(DataInputStream dis) throws IOException { + return new SaveInfo(dis); + } + + public void writeToStream(DataOutputStream dos) throws IOException { + dos.writeUTF(path); + dos.writeLong(time); + dos.writeInt(position); + dos.writeInt(variables.size()); + for (Map.Entry entry : variables.entrySet()) { + dos.writeUTF(entry.getKey()); + dos.writeDouble(entry.getValue()); + } + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(path); + dest.writeLong(time); + dest.writeInt(position); + dest.writeInt(variables.size()); + for (Map.Entry entry : variables.entrySet()) { + dest.writeString(entry.getKey()); + dest.writeDouble(entry.getValue()); + } + } + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + @Override + public SaveInfo createFromParcel(Parcel in) { + return new SaveInfo(in); + } + + @Override + public SaveInfo[] newArray(int size) { + return new SaveInfo[size]; + } + }; +}