/** JSON value to long: return a {@code long}, or the default value. */ public static long getLong(JsonValue jv, long dftValue) { if ( jv.isNumber() ) { Number num = jv.getAsNumber().value(); if ( num.doubleValue() < Long.MIN_VALUE || num.doubleValue() > Long.MAX_VALUE ) throw new NumberFormatException("Number out of range: "+jv); return num.longValue(); } return dftValue ; }
/** JSON value to int: return a {@code long}, or the default value. */ public static int getInt(JsonValue jv, int dftValue) { if ( jv.isNumber() ) { long z = jv.getAsNumber().value().longValue(); if ( z < Integer.MIN_VALUE || z > Integer.MAX_VALUE ) throw new NumberFormatException("Number out of range: "+jv); return (int)z; } return dftValue ; }
private static Integer getInt(JsonObject json, String key) { if ( ! json.hasKey(key) ) throw new TDBException("StoreParamsCodec.getInt: no such key: "+key) ; Integer x = json.get(key).getAsNumber().value().intValue() ; return x ; }
private static Integer getInt(JsonObject json, String key) { if ( ! json.hasKey(key) ) throw new TDBException("StoreParamsCodec.getInt: no such key: "+key) ; Integer x = json.get(key).getAsNumber().value().intValue() ; return x ; }
private void parseConf(BackupConfig cfg, String cfgFile) { try { JsonObject obj = JSON.read(cfgFile); cfg.port = obj.get(jPort).getAsNumber().value().intValue(); JsonArray a = obj.get(jLogs).getAsArray(); a.forEach(elt-> { BackupArea area = parseLogObject(cfg, elt); cfg.logs.add(area); }); } catch (Exception ex) { throw new CmdException("Failed to process configuration file: "+ex.getMessage()); } }
private void jsonSetState(JsonObject obj) { try { FmtLog.debug(LOG, "jsonToState %s",JSON.toStringFlat(obj)); long ver = obj.get(fVersion).getAsNumber().value().longValue(); if ( ver == version ) return ; Id newCurrent = getIdOrNull(obj, fId); Id newPrevious = getIdOrNull(obj, fPrevious); newState(ver, newCurrent, newPrevious); } catch (RuntimeException ex) { FmtLog.error(this.getClass(), "Failed to load the patch log index state", ex); } }
JsonObject next = execJsonItems.next(); if (next.get("s").toString().contains("first")) { assertEquals(123, next.get("o").getAsNumber().value().intValue()); } else if (next.get("s").toString().contains("second")) { assertEquals("abc", next.get("o").getAsString().value());