Добавлен класс SaveInfo
This commit is contained in:
parent
3a35115bef
commit
7f31e7edb9
128
src/com/annimon/everlastingsummer/SaveInfo.java
Normal file
128
src/com/annimon/everlastingsummer/SaveInfo.java
Normal file
@ -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<String, Double> variables;
|
||||||
|
|
||||||
|
public SaveInfo() {}
|
||||||
|
|
||||||
|
public SaveInfo(String path, long time, int position, Map<String, Double> 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<String, Double>(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<String, Double>(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<String, Double> getVariables() {
|
||||||
|
return variables;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVariables(Map<String, Double> 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<String, Double> 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<String, Double> entry : variables.entrySet()) {
|
||||||
|
dest.writeString(entry.getKey());
|
||||||
|
dest.writeDouble(entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Parcelable.Creator<SaveInfo> CREATOR = new Parcelable.Creator<SaveInfo>() {
|
||||||
|
@Override
|
||||||
|
public SaveInfo createFromParcel(Parcel in) {
|
||||||
|
return new SaveInfo(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SaveInfo[] newArray(int size) {
|
||||||
|
return new SaveInfo[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user