Java Code Examples for org.codehaus.jettison.json.JSONObject#getDouble()

The following examples show how to use org.codehaus.jettison.json.JSONObject#getDouble() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@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);
  }
}
 
Example 2
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");
  }
}
 
Example 3
Source Project: hadoop-arch-book   File: UserEvent.java    License: Apache License 2.0 5 votes vote down vote up
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");
}
 
Example 4
Source Project: hadoop-arch-book   File: UserProfile.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 5
private void verifySubQueue(JSONObject info, String q, 
    float parentAbsCapacity, float parentAbsMaxCapacity)
    throws JSONException, Exception {
  int numExpectedElements = 13;
  boolean isParentQueue = true;
  if (!info.has("queues")) {
    numExpectedElements = 25;
    isParentQueue = false;
  }
  assertEquals("incorrect number of elements", numExpectedElements, info.length());

  QueueInfo qi = isParentQueue ? new QueueInfo() : new LeafQueueInfo();
  qi.capacity = (float) info.getDouble("capacity");
  qi.usedCapacity = (float) info.getDouble("usedCapacity");
  qi.maxCapacity = (float) info.getDouble("maxCapacity");
  qi.absoluteCapacity = (float) info.getDouble("absoluteCapacity");
  qi.absoluteMaxCapacity = (float) info.getDouble("absoluteMaxCapacity");
  qi.absoluteUsedCapacity = (float) info.getDouble("absoluteUsedCapacity");
  qi.numApplications = info.getInt("numApplications");
  qi.queueName = info.getString("queueName");
  qi.state = info.getString("state");

  verifySubQueueGeneric(q, qi, parentAbsCapacity, parentAbsMaxCapacity);

  if (isParentQueue) {
    JSONArray arr = info.getJSONObject("queues").getJSONArray("queue");
    // test subqueues
    for (int i = 0; i < arr.length(); i++) {
      JSONObject obj = arr.getJSONObject(i);
      String q2 = q + "." + obj.getString("queueName");
      verifySubQueue(obj, q2, qi.absoluteCapacity, qi.absoluteMaxCapacity);
    }
  } else {
    LeafQueueInfo lqi = (LeafQueueInfo) qi;
    lqi.numActiveApplications = info.getInt("numActiveApplications");
    lqi.numPendingApplications = info.getInt("numPendingApplications");
    lqi.numContainers = info.getInt("numContainers");
    lqi.maxApplications = info.getInt("maxApplications");
    lqi.maxApplicationsPerUser = info.getInt("maxApplicationsPerUser");
    lqi.userLimit = info.getInt("userLimit");
    lqi.userLimitFactor = (float) info.getDouble("userLimitFactor");
    verifyLeafQueueGeneric(q, lqi);
    // resourcesUsed and users (per-user resources used) are checked in
    // testPerUserResource()
  }
}
 
Example 6
private void verifySubQueue(JSONObject info, String q, 
    float parentAbsCapacity, float parentAbsMaxCapacity)
    throws JSONException, Exception {
  int numExpectedElements = 13;
  boolean isParentQueue = true;
  if (!info.has("queues")) {
    numExpectedElements = 25;
    isParentQueue = false;
  }
  assertEquals("incorrect number of elements", numExpectedElements, info.length());

  QueueInfo qi = isParentQueue ? new QueueInfo() : new LeafQueueInfo();
  qi.capacity = (float) info.getDouble("capacity");
  qi.usedCapacity = (float) info.getDouble("usedCapacity");
  qi.maxCapacity = (float) info.getDouble("maxCapacity");
  qi.absoluteCapacity = (float) info.getDouble("absoluteCapacity");
  qi.absoluteMaxCapacity = (float) info.getDouble("absoluteMaxCapacity");
  qi.absoluteUsedCapacity = (float) info.getDouble("absoluteUsedCapacity");
  qi.numApplications = info.getInt("numApplications");
  qi.queueName = info.getString("queueName");
  qi.state = info.getString("state");

  verifySubQueueGeneric(q, qi, parentAbsCapacity, parentAbsMaxCapacity);

  if (isParentQueue) {
    JSONArray arr = info.getJSONObject("queues").getJSONArray("queue");
    // test subqueues
    for (int i = 0; i < arr.length(); i++) {
      JSONObject obj = arr.getJSONObject(i);
      String q2 = q + "." + obj.getString("queueName");
      verifySubQueue(obj, q2, qi.absoluteCapacity, qi.absoluteMaxCapacity);
    }
  } else {
    LeafQueueInfo lqi = (LeafQueueInfo) qi;
    lqi.numActiveApplications = info.getInt("numActiveApplications");
    lqi.numPendingApplications = info.getInt("numPendingApplications");
    lqi.numContainers = info.getInt("numContainers");
    lqi.maxApplications = info.getInt("maxApplications");
    lqi.maxApplicationsPerUser = info.getInt("maxApplicationsPerUser");
    lqi.userLimit = info.getInt("userLimit");
    lqi.userLimitFactor = (float) info.getDouble("userLimitFactor");
    verifyLeafQueueGeneric(q, lqi);
    // resourcesUsed and users (per-user resources used) are checked in
    // testPerUserResource()
  }
}