Created
February 19, 2014 04:37
-
-
Save ymhuang0808/9086124 to your computer and use it in GitHub Desktop.
StationHashMap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StationHashMap implements Parcelable { | |
private HashMap<String, Station> mStationMap = new HashMap<String, Station>(); | |
public StationHashMap() { | |
} | |
public void setStationMap(HashMap<String, Station> stationMap) { | |
mStationMap = stationMap; | |
} | |
public HashMap<String, Station> getStationMap() { | |
return mStationMap; | |
} | |
@Override | |
public int describeContents() { | |
return 0; | |
} | |
@Override | |
public void writeToParcel(Parcel dest, int flags) { | |
Log.d(this.toString(), "in writeToParcel()"); | |
final int mapSize = mStationMap.size(); | |
dest.writeInt(mapSize); | |
if (mapSize > 0) { | |
for (Map.Entry<String, Station> entry : mStationMap.entrySet()) { | |
dest.writeString(entry.getKey()); | |
Station station = entry.getValue(); | |
dest.writeInt(station.getId()); | |
dest.writeInt(station.getNo()); | |
dest.writeString(station.getName()); | |
dest.writeString(station.getAddress()); | |
dest.writeDouble(station.getLat()); | |
dest.writeDouble(station.getLng()); | |
dest.writeString(station.getDesc()); | |
dest.writeInt(station.getBikeNum()); | |
dest.writeInt(station.getEmptyNum()); | |
} | |
} | |
} | |
public static final Creator<StationHashMap> CREATOR = new Creator<StationHashMap>() { | |
@Override | |
public StationHashMap createFromParcel(Parcel source) { | |
return new StationHashMap(source); | |
} | |
@Override | |
public StationHashMap[] newArray(int size) { | |
return new StationHashMap[size]; | |
} | |
}; | |
private StationHashMap(Parcel source) { | |
Log.d(this.toString(), "in StationHashMap()"); | |
final int mapSize = source.readInt(); | |
for (int i = 0; i < mapSize; i++) { | |
String key = source.readString(); | |
Station station = new Station(); | |
station.setId(source.readInt()); | |
station.setNo(source.readInt()); | |
station.setName(source.readString()); | |
station.setAddress(source.readString()); | |
station.setLat(source.readDouble()); | |
station.setLng(source.readDouble()); | |
station.setDesc(source.readString()); | |
station.setBikeNum(source.readInt()); | |
station.setEmptyNum(source.readInt()); | |
mStationMap.put(key, station); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment