private int doGetInt(String key, Object o) throws JSONException { return o instanceof Number ? ((Number)o).intValue() : (int)getDouble(key); }
private long doGetLong(String key, Object o) throws JSONException { return o instanceof String ? Long.parseLong(((String)o)) : o instanceof Number ? ((Number)o).longValue() : (long)getDouble(key); }
/** * latitude in decimal degrees (wgs84) * * @return the latitude. */ public double getLatitude() { try { return data.getDouble(ToponymProperty.lat.name()); } catch (JSONException e) { throw new IllegalStateException(String.format("Unable to parse %s form %s", ToponymProperty.lat, data)); } }
/** * Get the int value associated with a key. If the number value is too * large for an int, it will be clipped. * * @param key A key string. * @return The integer value. * @throws JSONException if the key is not found or if the value cannot * be converted to an integer. */ public int getInt(String key) throws JSONException { Object o = get(key); return o instanceof Number ? ((Number)o).intValue() : (int)getDouble(key); }
/** * Get the long value associated with a key. If the number value is too * long for a long, it will be clipped. * * @param key A key string. * @return The long value. * @throws JSONException if the key is not found or if the value cannot * be converted to a long. */ public long getLong(String key) throws JSONException { Object o = get(key); return o instanceof Number ? ((Number)o).longValue() : (long)getDouble(key); }
/** * longitude in decimal degrees (wgs84) * * @return the longitude. */ public double getLongitude() { try { return data.getDouble(ToponymProperty.lng.name()); } catch (JSONException e) { throw new IllegalStateException(String.format("Unable to parse %s form %s", ToponymProperty.lng, data)); } }
public UserProfile(JSONObject jsonObject) throws JSONException { userId = jsonObject.getString("userId"); historicAvgSingleDaySpend = jsonObject.getDouble("historicAvgSingleDaySpend"); historicAvg90PercentSingleDaySpend = jsonObject.getDouble("historicAvg90PercentSingleDaySpend"); todayMaxSpend = jsonObject.getDouble("todayMaxSpend"); todayNumOfPurchases = jsonObject.getLong("todayNumOfPurchases"); populateMapWithLong(jsonObject.getJSONObject("spendByLast100VenderId"), spendByLast100VenderId); }
public ValidationRules(JSONObject jsonObject) throws JSONException { if (jsonObject != null) { JSONArray jsonArray = jsonObject.getJSONArray("bannedVanderIds"); for (int i = 0; i < jsonArray.length(); i++) { String bannedId = jsonArray.getString(i); LOG.info(" - Adding bannded venderId:" + bannedId); bannedVanderIdSet.add(bannedId); } thresholdInSpendDifferenceFromTodayFromPastMonthAverage = jsonObject.getDouble("thresholdInSpendDifferenceFromTodayFromPastMonthAverage"); } else { LOG.warn("No Validation Rules Found in HBase"); } }
public Double getScore() { try { if (data.has(ToponymProperty.score.name())) { return data.getDouble(ToponymProperty.score.name()); } else { return null; } } catch (JSONException e) { throw new IllegalStateException(String.format("Unable to parse %s form %s", ToponymProperty.score, data)); } }
@Override protected void processQuery(String queryStr) { try { JSONObject query = new JSONObject(queryStr); JSONObject result = new JSONObject(); double lat = query.getDouble("lat"); double lon = query.getDouble("lon"); Pair<String, String> zips = recommendZip(lat, lon); result.put("currentZip", zips.getLeft()); result.put("driveToZip", zips.getRight()); resultQueue.add(result.toString()); } catch (JSONException e) { LOG.error("Unrecognized query: {}", queryStr); } }
private void verifyPartitionCapacityInfoJson( JSONObject partitionCapacityInfoJson, float capacity, float usedCapacity, float maxCapacity, float absoluteCapacity, float absoluteUsedCapacity, float absoluteMaxCapacity) throws JSONException { assertEquals("capacity doesn't match", capacity, (float) partitionCapacityInfoJson.getDouble("capacity"), 1e-3f); assertEquals("capacity doesn't match", usedCapacity, (float) partitionCapacityInfoJson.getDouble("usedCapacity"), 1e-3f); assertEquals("capacity doesn't match", maxCapacity, (float) partitionCapacityInfoJson.getDouble("maxCapacity"), 1e-3f); assertEquals("capacity doesn't match", absoluteCapacity, (float) partitionCapacityInfoJson.getDouble("absoluteCapacity"), 1e-3f); assertEquals("capacity doesn't match", absoluteUsedCapacity, (float) partitionCapacityInfoJson.getDouble("absoluteUsedCapacity"), 1e-3f); assertEquals("capacity doesn't match", absoluteMaxCapacity, (float) partitionCapacityInfoJson.getDouble("absoluteMaxCapacity"), 1e-3f); } }
public UserEvent(JSONObject jsonObject) throws JSONException { userId = jsonObject.getString("userId"); timeStamp = jsonObject.getLong("timeStamp"); ipAddress = jsonObject.getString("ipAddress"); countryCode = jsonObject.getString("countryCode"); zipCode = jsonObject.getString("zipCode"); itemCategory = jsonObject.getString("itemCategory"); paymentAmount = jsonObject.getDouble("paymentAmount"); vendorId = jsonObject.getString("vendorId"); isCardPresent = jsonObject.getBoolean("isCardPresent"); }
private void verifyClusterScheduler(JSONObject json) throws JSONException, Exception { assertEquals("incorrect number of elements", 1, json.length()); JSONObject info = json.getJSONObject("scheduler"); assertEquals("incorrect number of elements", 1, info.length()); info = info.getJSONObject("schedulerInfo"); assertEquals("incorrect number of elements", 6, info.length()); verifyClusterSchedulerGeneric(info.getString("type"), (float) info.getDouble("usedCapacity"), (float) info.getDouble("capacity"), (float) info.getDouble("maxCapacity"), info.getString("queueName")); JSONArray arr = info.getJSONObject("queues").getJSONArray("queue"); assertEquals("incorrect number of elements", 2, arr.length()); // test subqueues for (int i = 0; i < arr.length(); i++) { JSONObject obj = arr.getJSONObject(i); String q = CapacitySchedulerConfiguration.ROOT + "." + obj.getString("queueName"); verifySubQueue(obj, q, 100, 100); } }
public void verifyClusterSchedulerFifo(JSONObject json) throws JSONException, Exception { assertEquals("incorrect number of elements in: " + json, 1, json.length()); JSONObject info = json.getJSONObject("scheduler"); assertEquals("incorrect number of elements in: " + info, 1, info.length()); info = info.getJSONObject("schedulerInfo"); LOG.debug("schedulerInfo: {}", info); assertEquals("incorrect number of elements in: " + info, 11, info.length()); verifyClusterSchedulerFifoGeneric(info.getString("type"), info.getString("qstate"), (float) info.getDouble("capacity"), (float) info.getDouble("usedCapacity"), info.getInt("minQueueMemoryCapacity"), info.getInt("maxQueueMemoryCapacity"), info.getInt("numNodes"), info.getInt("usedNodeCapacity"), info.getInt("availNodeCapacity"), info.getInt("totalNodeCapacity"), info.getInt("numContainers")); }
private boolean sameScalar(ScalarValue want, JSONObject parent, String name) throws Exception { trace("comparing object scalar property " + name); String regexp = want.getRegexp(); if (want instanceof StringValue) { return sameString(((StringValue) want).getValue(), regexp, parent.getString(name)); } if (want instanceof LongValue) { return sameString(longToString(((LongValue) want).getValue()), regexp, longToString(parent.getLong(name))); } if (want instanceof IntValue) { return sameString(intToString(((IntValue) want).getValue()), regexp, intToString(parent.getInt(name))); } if (want instanceof DoubleValue) { return sameString(doubleToString(((DoubleValue) want).getValue()), regexp, doubleToString(parent.getDouble(name))); } if (want instanceof BooleanValue) { return sameString(booleanToString(((BooleanValue) want).getValue()), regexp, booleanToString(parent.getBoolean(name))); } throw new AssertionError(want + " is not a valid scalar type. Valid types are string, long, int, double, boolean"); }
public void verifyClusterSchedulerFifo(JSONObject json) throws JSONException, Exception { assertEquals("incorrect number of elements", 1, json.length()); JSONObject info = json.getJSONObject("scheduler"); assertEquals("incorrect number of elements", 1, info.length()); info = info.getJSONObject("schedulerInfo"); assertEquals("incorrect number of elements", 11, info.length()); verifyClusterSchedulerFifoGeneric(info.getString("type"), info.getString("qstate"), (float) info.getDouble("capacity"), (float) info.getDouble("usedCapacity"), info.getInt("minQueueMemoryCapacity"), info.getInt("maxQueueMemoryCapacity"), info.getInt("numNodes"), info.getInt("usedNodeCapacity"), info.getInt("availNodeCapacity"), info.getInt("totalNodeCapacity"), info.getInt("numContainers")); }
public void verifyAMSingleTask(JSONObject info, Task task) throws JSONException { assertEquals("incorrect number of elements", 9, info.length()); verifyTaskGeneric(task, info.getString("id"), info.getString("state"), info.getString("type"), info.getString("successfulAttempt"), info.getLong("startTime"), info.getLong("finishTime"), info.getLong("elapsedTime"), (float) info.getDouble("progress"), info.getString("status")); }
public void verifyAMTaskAttempt(JSONObject info, TaskAttempt att, TaskType ttype) throws JSONException { if (ttype == TaskType.REDUCE) { assertEquals("incorrect number of elements", 17, info.length()); } else { assertEquals("incorrect number of elements", 12, info.length()); } verifyTaskAttemptGeneric(att, ttype, info.getString("id"), info.getString("state"), info.getString("type"), info.getString("rack"), info.getString("nodeHttpAddress"), info.getString("diagnostics"), info.getString("assignedContainerId"), info.getLong("startTime"), info.getLong("finishTime"), info.getLong("elapsedTime"), (float) info.getDouble("progress")); if (ttype == TaskType.REDUCE) { verifyReduceTaskAttemptGeneric(att, info.getLong("shuffleFinishTime"), info.getLong("mergeFinishTime"), info.getLong("elapsedShuffleTime"), info.getLong("elapsedMergeTime"), info.getLong("elapsedReduceTime")); } }
public void verifyAppInfo(JSONObject info, RMApp app) throws JSONException, Exception { assertEquals("incorrect number of elements", 27, info.length()); verifyAppInfoGeneric(app, info.getString("id"), info.getString("user"), info.getString("name"), info.getString("applicationType"), info.getString("queue"), info.getString("state"), info.getString("finalStatus"), (float) info.getDouble("progress"), info.getString("trackingUI"), info.getString("diagnostics"), info.getLong("clusterId"), info.getLong("startedTime"), info.getLong("finishedTime"), info.getLong("elapsedTime"), info.getString("amHostHttpAddress"), info.getString("amContainerLogs"), info.getInt("allocatedMB"), info.getInt("allocatedVCores"), info.getInt("runningContainers"), info.getInt("preemptedResourceMB"), info.getInt("preemptedResourceVCores"), info.getInt("numNonAMContainerPreempted"), info.getInt("numAMContainerPreempted")); }