我无法理解这一点。我的情况是:
我的代码是这样的:
boolean isSubscriberToCtnMapEmpty = false;
Map<String, Type> subscriberWithType = new HashMap<String, Type>();
Map<String, String> subscriberToCtnMap = getMapFromSession(HttpServletRequest)
if (subscriberToCtnMap == null || subscriberToCtnMap.isEmpty()) {
isSubscriberToCtnMapEmpty = true;
}
for (MobileNumber mobile : ListOfMobiles) {
String subscriber = mobile.getSubscriberId();
if (subscriber != null) {
subscriberWithType.put(subscriber, Type.SUB_ID);
if (isSubscriberToCtnMapEmpty)
subscriberToCtnMap.put(subscriber, mobile.getMobileNumber());
} else {
subscriberWithType.put(mobile.getMobileNumber(), Type.MOBILE);
//No need to put the entry in subscriberToCtnMap as subscriber is NULL
}
}
//Set the subscriberToCtnMap in Session if not set already
if (isSubscriberToCtnMapEmpty) {
session.setSubscriberToCtnMapping(subscriberToCtnMap);
}
如何提高上述逻辑的编码质量?
谢谢!
答案 0 :(得分:0)
您的测试public EarthquakeLoader(Context context, String url) {
super(context);
this.mUrl = url;
}
@Override
public List<Earthquake> loadInBackground() {
Log.e(LOG_TAG, "loadInBackGround()");
List<Earthquake> earthquakes = QueryUtils.extractEarthquakes(this.mUrl);
return earthquakes;
}
@Override
public void onStartLoading() {
Log.e(LOG_TAG, "onStartLoading()");
forceLoad();
}
@Override
public void onStopLoading() {
super.onStopLoading();
Log.e(LOG_TAG, "onStopLoading()");
}
public void onReset() {
super.onReset();
Log.e(LOG_TAG, "onReset()");
}
subscriberToCtnMap`为空或空,完全相反。它们应该是这样的:
if (isSubscriberToCtnMapEmpty)...', no doubt intended to defend against the possibility of