Fix nomenclature for RequestInfo types [1/2]

- Renamed TYPE_GEO_LOCATION_REQ to TYPE_WEATHER_BY_GEO_LOCATION_REQ
  and TYPE_WEATHER_LOCATION_REQ to TYPE_WEATHER_BY_WEATHER_LCATION_REQ
- Prevent null argument on setter methods. Documentation updated to
  warn user of IllegalArgumentException if null is passed

Change-Id: I6ba8fb7fb3a10d8c964414b58e00d9ce77a74e84
TICKET: CYNGNOS-2377
This commit is contained in:
Luis Vidal 2016-04-08 13:19:48 -07:00
parent baaf4a1baf
commit 34bf4866db
5 changed files with 46 additions and 32 deletions

View File

@ -1335,9 +1335,9 @@ package cyanogenmod.weather {
method public cyanogenmod.weather.WeatherLocation getWeatherLocation(); method public cyanogenmod.weather.WeatherLocation getWeatherLocation();
method public void writeToParcel(android.os.Parcel, int); method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<cyanogenmod.weather.RequestInfo> CREATOR; field public static final android.os.Parcelable.Creator<cyanogenmod.weather.RequestInfo> CREATOR;
field public static final int TYPE_GEO_LOCATION_REQ = 1; // 0x1
field public static final int TYPE_LOOKUP_CITY_NAME_REQ = 3; // 0x3 field public static final int TYPE_LOOKUP_CITY_NAME_REQ = 3; // 0x3
field public static final int TYPE_WEATHER_LOCATION_REQ = 2; // 0x2 field public static final int TYPE_WEATHER_BY_GEO_LOCATION_REQ = 1; // 0x1
field public static final int TYPE_WEATHER_BY_WEATHER_LOCATION_REQ = 2; // 0x2
} }
public final class WeatherInfo implements android.os.Parcelable { public final class WeatherInfo implements android.os.Parcelable {

View File

@ -91,8 +91,8 @@ public class CMWeatherManagerService extends SystemService{
final int requestType = requestInfo.getRequestType(); final int requestType = requestInfo.getRequestType();
switch (requestType) { switch (requestType) {
case RequestInfo.TYPE_GEO_LOCATION_REQ: case RequestInfo.TYPE_WEATHER_BY_GEO_LOCATION_REQ:
case RequestInfo.TYPE_WEATHER_LOCATION_REQ: case RequestInfo.TYPE_WEATHER_BY_WEATHER_LOCATION_REQ:
if (!isValidRequestInfoState(requestType, state)) { if (!isValidRequestInfoState(requestType, state)) {
//We received an invalid state, silently disregard the request //We received an invalid state, silently disregard the request
mIsProcessingRequest = false; mIsProcessingRequest = false;
@ -142,8 +142,8 @@ public class CMWeatherManagerService extends SystemService{
private boolean isValidRequestInfoState(int requestType, int state) { private boolean isValidRequestInfoState(int requestType, int state) {
switch (requestType) { switch (requestType) {
case RequestInfo.TYPE_GEO_LOCATION_REQ: case RequestInfo.TYPE_WEATHER_BY_GEO_LOCATION_REQ:
case RequestInfo.TYPE_WEATHER_LOCATION_REQ: case RequestInfo.TYPE_WEATHER_BY_WEATHER_LOCATION_REQ:
switch (state) { switch (state) {
case CMWeatherManager.WEATHER_REQUEST_COMPLETED: case CMWeatherManager.WEATHER_REQUEST_COMPLETED:
case CMWeatherManager.WEATHER_REQUEST_SUBMITTED_TOO_SOON: case CMWeatherManager.WEATHER_REQUEST_SUBMITTED_TOO_SOON:

View File

@ -42,11 +42,11 @@ public final class RequestInfo implements Parcelable {
/** /**
* A request to update the weather data using a geographical {@link android.location.Location} * A request to update the weather data using a geographical {@link android.location.Location}
*/ */
public static final int TYPE_GEO_LOCATION_REQ = 1; public static final int TYPE_WEATHER_BY_GEO_LOCATION_REQ = 1;
/** /**
* A request to update the weather data using a {@link WeatherLocation} * A request to update the weather data using a {@link WeatherLocation}
*/ */
public static final int TYPE_WEATHER_LOCATION_REQ = 2; public static final int TYPE_WEATHER_BY_WEATHER_LOCATION_REQ = 2;
/** /**
* A request to look up a city name * A request to look up a city name
@ -70,9 +70,13 @@ public final class RequestInfo implements Parcelable {
/** /**
* Sets the city name and identifies this request as a {@link #TYPE_LOOKUP_CITY_NAME_REQ} * Sets the city name and identifies this request as a {@link #TYPE_LOOKUP_CITY_NAME_REQ}
* request. If set, will null out the location and weather location. * request. If set, will null out the location and weather location. Attempting to set
* a null city name will get you an IllegalArgumentException
*/ */
public Builder setCityName(String cityName) { public Builder setCityName(String cityName) {
if (cityName == null) {
throw new IllegalArgumentException("City name can't be null");
}
this.mCityName = cityName; this.mCityName = cityName;
this.mRequestType = TYPE_LOOKUP_CITY_NAME_REQ; this.mRequestType = TYPE_LOOKUP_CITY_NAME_REQ;
this.mLocation = null; this.mLocation = null;
@ -81,26 +85,36 @@ public final class RequestInfo implements Parcelable {
} }
/** /**
* Sets the Location and identifies this request as a {@link #TYPE_GEO_LOCATION_REQ}. If * Sets the Location and identifies this request as a
* set, will null out the city name and weather location. * {@link #TYPE_WEATHER_BY_GEO_LOCATION_REQ}. If set, will null out the city name and
* weather location. Attempting to set a null location will get you an
* IllegalArgumentException
*/ */
public Builder setLocation(Location location) { public Builder setLocation(Location location) {
if (location == null) {
throw new IllegalArgumentException("Location can't be null");
}
this.mLocation = new Location(location); this.mLocation = new Location(location);
this.mCityName = null; this.mCityName = null;
this.mWeatherLocation = null; this.mWeatherLocation = null;
this.mRequestType = TYPE_GEO_LOCATION_REQ; this.mRequestType = TYPE_WEATHER_BY_GEO_LOCATION_REQ;
return this; return this;
} }
/** /**
* Sets the weather location and identifies this request as a * Sets the weather location and identifies this request as a
* {@link #TYPE_WEATHER_LOCATION_REQ}. If set, will null out the location and city name * {@link #TYPE_WEATHER_BY_WEATHER_LOCATION_REQ}. If set, will null out the location and
* city name. Attempting to set a null weather location will get you an
* IllegalArgumentException
*/ */
public Builder setWeatherLocation(WeatherLocation weatherLocation) { public Builder setWeatherLocation(WeatherLocation weatherLocation) {
if (weatherLocation == null) {
throw new IllegalArgumentException("WeatherLocation can't be null");
}
this.mWeatherLocation = weatherLocation; this.mWeatherLocation = weatherLocation;
this.mLocation = null; this.mLocation = null;
this.mCityName = null; this.mCityName = null;
this.mRequestType = TYPE_WEATHER_LOCATION_REQ; this.mRequestType = TYPE_WEATHER_BY_WEATHER_LOCATION_REQ;
return this; return this;
} }
@ -130,8 +144,8 @@ public final class RequestInfo implements Parcelable {
*/ */
public Builder queryOnly() { public Builder queryOnly() {
switch (mRequestType) { switch (mRequestType) {
case TYPE_GEO_LOCATION_REQ: case TYPE_WEATHER_BY_GEO_LOCATION_REQ:
case TYPE_WEATHER_LOCATION_REQ: case TYPE_WEATHER_BY_WEATHER_LOCATION_REQ:
this.mIsQueryOnly = true; this.mIsQueryOnly = true;
break; break;
default: default:
@ -175,11 +189,11 @@ public final class RequestInfo implements Parcelable {
mKey = parcel.readInt(); mKey = parcel.readInt();
mRequestType = parcel.readInt(); mRequestType = parcel.readInt();
switch (mRequestType) { switch (mRequestType) {
case TYPE_GEO_LOCATION_REQ: case TYPE_WEATHER_BY_GEO_LOCATION_REQ:
mLocation = Location.CREATOR.createFromParcel(parcel); mLocation = Location.CREATOR.createFromParcel(parcel);
mTempUnit = parcel.readInt(); mTempUnit = parcel.readInt();
break; break;
case TYPE_WEATHER_LOCATION_REQ: case TYPE_WEATHER_BY_WEATHER_LOCATION_REQ:
mWeatherLocation = WeatherLocation.CREATOR.createFromParcel(parcel); mWeatherLocation = WeatherLocation.CREATOR.createFromParcel(parcel);
mTempUnit = parcel.readInt(); mTempUnit = parcel.readInt();
break; break;
@ -238,8 +252,8 @@ public final class RequestInfo implements Parcelable {
*/ */
public int getTemperatureUnit() { public int getTemperatureUnit() {
switch (mRequestType) { switch (mRequestType) {
case TYPE_GEO_LOCATION_REQ: case TYPE_WEATHER_BY_GEO_LOCATION_REQ:
case TYPE_WEATHER_LOCATION_REQ: case TYPE_WEATHER_BY_WEATHER_LOCATION_REQ:
return mTempUnit; return mTempUnit;
default: default:
return -1; return -1;
@ -253,8 +267,8 @@ public final class RequestInfo implements Parcelable {
*/ */
public boolean isQueryOnlyWeatherRequest() { public boolean isQueryOnlyWeatherRequest() {
switch (mRequestType) { switch (mRequestType) {
case TYPE_GEO_LOCATION_REQ: case TYPE_WEATHER_BY_GEO_LOCATION_REQ:
case TYPE_WEATHER_LOCATION_REQ: case TYPE_WEATHER_BY_WEATHER_LOCATION_REQ:
return mIsQueryOnly; return mIsQueryOnly;
default: default:
return false; return false;
@ -287,11 +301,11 @@ public final class RequestInfo implements Parcelable {
dest.writeInt(mKey); dest.writeInt(mKey);
dest.writeInt(mRequestType); dest.writeInt(mRequestType);
switch (mRequestType) { switch (mRequestType) {
case TYPE_GEO_LOCATION_REQ: case TYPE_WEATHER_BY_GEO_LOCATION_REQ:
mLocation.writeToParcel(dest, 0); mLocation.writeToParcel(dest, 0);
dest.writeInt(mTempUnit); dest.writeInt(mTempUnit);
break; break;
case TYPE_WEATHER_LOCATION_REQ: case TYPE_WEATHER_BY_WEATHER_LOCATION_REQ:
mWeatherLocation.writeToParcel(dest, 0); mWeatherLocation.writeToParcel(dest, 0);
dest.writeInt(mTempUnit); dest.writeInt(mTempUnit);
break; break;
@ -311,7 +325,7 @@ public final class RequestInfo implements Parcelable {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("{ Request for "); builder.append("{ Request for ");
switch (mRequestType) { switch (mRequestType) {
case TYPE_GEO_LOCATION_REQ: case TYPE_WEATHER_BY_GEO_LOCATION_REQ:
builder.append("Location: ").append(mLocation); builder.append("Location: ").append(mLocation);
builder.append(" Temp Unit: "); builder.append(" Temp Unit: ");
if (mTempUnit == WeatherContract.WeatherColumns.TempUnit.FAHRENHEIT) { if (mTempUnit == WeatherContract.WeatherColumns.TempUnit.FAHRENHEIT) {
@ -320,7 +334,7 @@ public final class RequestInfo implements Parcelable {
builder.append(" Celsius"); builder.append(" Celsius");
} }
break; break;
case TYPE_WEATHER_LOCATION_REQ: case TYPE_WEATHER_BY_WEATHER_LOCATION_REQ:
builder.append("WeatherLocation: ").append(mWeatherLocation); builder.append("WeatherLocation: ").append(mWeatherLocation);
builder.append(" Temp Unit: "); builder.append(" Temp Unit: ");
if (mTempUnit == WeatherContract.WeatherColumns.TempUnit.FAHRENHEIT) { if (mTempUnit == WeatherContract.WeatherColumns.TempUnit.FAHRENHEIT) {

View File

@ -56,8 +56,8 @@ public final class ServiceRequest {
try { try {
final int requestType = mInfo.getRequestType(); final int requestType = mInfo.getRequestType();
switch (requestType) { switch (requestType) {
case RequestInfo.TYPE_GEO_LOCATION_REQ: case RequestInfo.TYPE_WEATHER_BY_GEO_LOCATION_REQ:
case RequestInfo.TYPE_WEATHER_LOCATION_REQ: case RequestInfo.TYPE_WEATHER_BY_WEATHER_LOCATION_REQ:
if (result.getWeatherInfo() == null) { if (result.getWeatherInfo() == null) {
throw new IllegalStateException("The service request result does not" throw new IllegalStateException("The service request result does not"
+ " contain a valid WeatherInfo object"); + " contain a valid WeatherInfo object");
@ -91,8 +91,8 @@ public final class ServiceRequest {
try { try {
final int requestType = mInfo.getRequestType(); final int requestType = mInfo.getRequestType();
switch (requestType) { switch (requestType) {
case RequestInfo.TYPE_GEO_LOCATION_REQ: case RequestInfo.TYPE_WEATHER_BY_GEO_LOCATION_REQ:
case RequestInfo.TYPE_WEATHER_LOCATION_REQ: case RequestInfo.TYPE_WEATHER_BY_WEATHER_LOCATION_REQ:
mClient.setServiceRequestState(mInfo, null, mClient.setServiceRequestState(mInfo, null,
CMWeatherManager.WEATHER_REQUEST_FAILED); CMWeatherManager.WEATHER_REQUEST_FAILED);
break; break;

View File

@ -1335,9 +1335,9 @@ package cyanogenmod.weather {
method public cyanogenmod.weather.WeatherLocation getWeatherLocation(); method public cyanogenmod.weather.WeatherLocation getWeatherLocation();
method public void writeToParcel(android.os.Parcel, int); method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<cyanogenmod.weather.RequestInfo> CREATOR; field public static final android.os.Parcelable.Creator<cyanogenmod.weather.RequestInfo> CREATOR;
field public static final int TYPE_GEO_LOCATION_REQ = 1; // 0x1
field public static final int TYPE_LOOKUP_CITY_NAME_REQ = 3; // 0x3 field public static final int TYPE_LOOKUP_CITY_NAME_REQ = 3; // 0x3
field public static final int TYPE_WEATHER_LOCATION_REQ = 2; // 0x2 field public static final int TYPE_WEATHER_BY_GEO_LOCATION_REQ = 1; // 0x1
field public static final int TYPE_WEATHER_BY_WEATHER_LOCATION_REQ = 2; // 0x2
} }
public final class WeatherInfo implements android.os.Parcelable { public final class WeatherInfo implements android.os.Parcelable {