Bug 730626 - Implement resetting. r=nalexander, a=blocking-fennec

This commit is contained in:
Richard Newman
2012-04-21 21:15:27 -07:00
parent 12330004a5
commit e52de266a3
22 changed files with 725 additions and 278 deletions

View File

@@ -131,6 +131,30 @@ public class ExtendedJSONObject {
return (String) this.get(key);
}
/**
* Return an Integer if the value for this key is an Integer, Long, or String
* that can be parsed as a base 10 Integer.
* Passes through null.
*
* @throws NumberFormatException
*/
public Integer getIntegerSafely(String key) throws NumberFormatException {
Object val = this.object.get(key);
if (val == null) {
return null;
}
if (val instanceof Integer) {
return (Integer) val;
}
if (val instanceof Long) {
return new Integer(((Long) val).intValue());
}
if (val instanceof String) {
return Integer.parseInt((String) val, 10);
}
throw new NumberFormatException("Expecting Integer, got " + val.getClass());
}
/**
* Return a server timestamp value as milliseconds since epoch.
* @param key