Address comments + add more tests.

This commit is contained in:
Sandor Dornbush
2010-12-19 22:11:41 -08:00
parent 878a87278d
commit fa711cf142
2 changed files with 64 additions and 21 deletions
@@ -40,13 +40,12 @@ public class WaypointCreationRequest implements Parcelable {
public final static WaypointCreationRequest DEFAULT_STATISTICS =
new WaypointCreationRequest(WaypointType.STATISTICS);
public WaypointCreationRequest(WaypointType type) {
private WaypointCreationRequest(WaypointType type) {
this.type = type;
}
public WaypointCreationRequest(WaypointType type, String name,
String description, String iconUrl) {
super();
this.type = type;
this.name = name;
this.description = description;
@@ -55,23 +54,19 @@ public class WaypointCreationRequest implements Parcelable {
public static class Creator implements Parcelable.Creator<WaypointCreationRequest> {
@Override
public WaypointCreationRequest createFromParcel(Parcel source) {
int i = source.readInt();
if (i > WaypointType.values().length) {
throw new IllegalArgumentException("Could not find waypoint type: " + i);
}
WaypointCreationRequest request = new WaypointCreationRequest(WaypointType.values()[i]);
request.description = maybeReadStringToParcel(source);
request.iconUrl = maybeReadStringToParcel(source);
request.name = maybeReadStringToParcel(source);
request.description = source.readString();
request.iconUrl = source.readString();
request.name = source.readString();
return request;
}
private String maybeReadStringToParcel(Parcel parcel) {
return parcel.readByte() > 0 ? parcel.readString() : null;
}
public WaypointCreationRequest[] newArray(int size) {
return new WaypointCreationRequest[size];
}
@@ -87,19 +82,11 @@ public class WaypointCreationRequest implements Parcelable {
@Override
public void writeToParcel(Parcel parcel, int arg1) {
parcel.writeInt(type.ordinal());
// TODO: Pack all of available bits into one byte.
maybeWriteStringToParcel(parcel, description);
maybeWriteStringToParcel(parcel, iconUrl);
maybeWriteStringToParcel(parcel, name);
parcel.writeString(description);
parcel.writeString(iconUrl);
parcel.writeString(name);
}
private void maybeWriteStringToParcel(Parcel parcel, String s) {
parcel.writeByte(s == null ? (byte) 0 : (byte) 1);
if (s != null) {
parcel.writeString(s);
}
}
public WaypointType getType() {
return type;
}