ExceptionToResourceMapping.java 源代码
package org.greenrobot.eventbus.util;
import android.util.Log;
import java.util.HashMap;
import java.util.Map;
public class ExceptionToResourceMapping {
public final Map<Class<? extends Throwable>, Integer> throwableToMsgIdMap = new HashMap();
public Integer mapThrowable(Throwable th) {
int i = 20;
Throwable th2 = th;
do {
Integer mapThrowableFlat = mapThrowableFlat(th2);
if (mapThrowableFlat == null) {
th2 = th2.getCause();
i--;
if (i <= 0 || th2 == th) {
break;
}
} else {
return mapThrowableFlat;
}
} while (th2 != null);
Log.d("EventBus", "No specific message resource ID found for " + th);
return null;
}
protected Integer mapThrowableFlat(Throwable th) {
Class<?> cls = th.getClass();
Integer num = this.throwableToMsgIdMap.get(cls);
if (num == null) {
Class<? extends Throwable> cls2 = null;
for (Map.Entry<Class<? extends Throwable>, Integer> entry : this.throwableToMsgIdMap.entrySet()) {
Class<? extends Throwable> key = entry.getKey();
if (key.isAssignableFrom(cls) && (cls2 == null || cls2.isAssignableFrom(key))) {
num = entry.getValue();
cls2 = key;
}
}
}
return num;
}
public ExceptionToResourceMapping addMapping(Class<? extends Throwable> cls, int i) {
this.throwableToMsgIdMap.put(cls, Integer.valueOf(i));
return this;
}
}