List of usage examples for com.google.gson JsonObject entrySet
public Set<Map.Entry<String, JsonElement>> entrySet()
From source file:com.apcb.utils.utils.HtmlTemplateReader.java
private SectionMatch readJson(JsonElement jsonElement, String from, SectionMatch sectionMatch) { //log.info(jsonElement.toString()); //SectionMatch sectionMatchChild = new SectionMatch(from); if (jsonElement.isJsonArray()) { //log.info("JsonArray"); JsonArray jsonArray = jsonElement.getAsJsonArray(); for (int i = 0; i < jsonArray.size(); i++) { SectionMatch sectionMatchArrayLevel = new SectionMatch(sectionMatch.getName()); sectionMatchArrayLevel.setIndex(i); sectionMatch.putChildens(readJson(jsonArray.get(i), from + "[" + i + "]", sectionMatchArrayLevel)); }/*from w w w .j a va 2 s. c o m*/ } else if (jsonElement.isJsonObject()) { //log.info("JsonObject"); JsonObject jsonObject = jsonElement.getAsJsonObject(); //since you know it's a JsonObject Set<Map.Entry<String, JsonElement>> entries = jsonObject.entrySet();//will return members of your object for (Map.Entry<String, JsonElement> entry : entries) { //log.info(entry.getKey()); sectionMatch.putChildens(readJson(jsonObject.get(entry.getKey()), from + "." + entry.getKey(), new SectionMatch(entry.getKey()))); } } else if (jsonElement.isJsonNull()) { log.info("JsonNull"); } else if (jsonElement.isJsonPrimitive()) { //log.info("JsonPrimitive"); String jsonVal = jsonElement.getAsString(); //from+= "."+entry.getKey(); sectionMatch.setValue(jsonVal); log.info(from + "=" + jsonVal); } return sectionMatch; }
From source file:com.appdynamics.extensions.couchbase.CouchBaseWrapper.java
License:Apache License
/** * Gathers Bucket Replication stats from /pools/default/buckets/<bucket_name>/stats * // w ww .jav a 2 s. c o m * Response contains all other stats but this only filters any stats that starts with 'replications', * e.g. replications/03cd3332434401c64594f47eeeabbb79/beer-sample/gamesim-sample/wtavg_meta_latency * * @param buckets * @param httpClient * @return Map<String, Map<String, Double>> */ public Map<String, Map<String, Double>> gatherOtherBucketMetrics(Set<String> buckets, SimpleHttpClient httpClient) { Map<String, Map<String, Double>> otherBucketMetrics = new HashMap<String, Map<String, Double>>(); if (buckets != null) { for (String bucket : buckets) { JsonElement bucketResponse = getResponse(httpClient, String.format(BUCKET_STATS_URI, bucket)); if (bucketResponse != null && bucketResponse.isJsonObject()) { JsonObject bucketStats = bucketResponse.getAsJsonObject(); JsonObject op = bucketStats.getAsJsonObject("op"); JsonObject samples = op.getAsJsonObject("samples"); populateOtherBucketMetrics(bucket, samples.entrySet().iterator(), otherBucketMetrics); } } } return otherBucketMetrics; }
From source file:com.appdynamics.extensions.couchbase.CouchBaseWrapper.java
License:Apache License
/** * Populates the cluster metrics hashmap * // w ww.j a v a 2 s . com * @param nodeMetrics * @param clusterStats * @return */ private Map<String, Map<String, Double>> populateClusterMetrics(Map<String, Map<String, Double>> nodeMetrics, JsonObject clusterStats) { Map<String, Double> clusterMetrics = new HashMap<String, Double>(); if (clusterStats != null) { JsonObject ramStats = clusterStats.getAsJsonObject("ram"); Iterator<Entry<String, JsonElement>> iterator = ramStats.entrySet().iterator(); populateMetricsMapHelper(iterator, clusterMetrics, "ram_"); JsonObject hddStats = clusterStats.getAsJsonObject("hdd"); iterator = hddStats.entrySet().iterator(); populateMetricsMapHelper(iterator, clusterMetrics, "hdd_"); } nodeMetrics.put(CLUSTER_STATS_KEY, clusterMetrics); return nodeMetrics; }
From source file:com.appdynamics.extensions.couchbase.CouchBaseWrapper.java
License:Apache License
/** * Populates the node metrics hashmap//www. j ava 2s . c om * * @param nodes * @return */ private Map<String, Map<String, Double>> populateNodeMetrics(JsonArray nodes) { Map<String, Map<String, Double>> nodeMetrics = new HashMap<String, Map<String, Double>>(); for (JsonElement node : nodes) { JsonObject nodeObject = node.getAsJsonObject(); Map<String, Double> metrics = new HashMap<String, Double>(); nodeMetrics.put(nodeObject.get("hostname").getAsString(), metrics); JsonObject interestingStats = nodeObject.getAsJsonObject("interestingStats"); Iterator<Entry<String, JsonElement>> iterator = interestingStats.entrySet().iterator(); populateMetricsMapHelper(iterator, metrics, ""); JsonObject systemStats = nodeObject.getAsJsonObject("systemStats"); iterator = systemStats.entrySet().iterator(); populateMetricsMapHelper(iterator, metrics, ""); iterator = nodeObject.entrySet().iterator(); populateMetricsMapHelper(iterator, metrics, ""); } return nodeMetrics; }
From source file:com.appdynamics.extensions.couchbase.CouchBaseWrapper.java
License:Apache License
/** * Populates the bucket metrics hashmap//from w ww . j a v a 2 s. c o m * * @param buckets * @return */ private Map<String, Map<String, Double>> populateBucketMetrics(JsonArray buckets) { Map<String, Map<String, Double>> bucketMetrics = new HashMap<String, Map<String, Double>>(); for (JsonElement bucket : buckets) { JsonObject bucketObject = bucket.getAsJsonObject(); Map<String, Double> metrics = new HashMap<String, Double>(); bucketMetrics.put(bucketObject.get("name").getAsString(), metrics); JsonObject interestingStats = bucketObject.getAsJsonObject("quota"); Iterator<Entry<String, JsonElement>> iterator = interestingStats.entrySet().iterator(); populateMetricsMapHelper(iterator, metrics, ""); JsonObject systemStats = bucketObject.getAsJsonObject("basicStats"); iterator = systemStats.entrySet().iterator(); populateMetricsMapHelper(iterator, metrics, ""); } return bucketMetrics; }
From source file:com.appdynamics.extensions.couchdb.CouchDBWrapper.java
License:Apache License
/** * Constructs a HashMap of metrics based on the JSON Response received upon * executing CouchDB's /_stats REST API request * //w w w . j a v a 2 s .c o m * @param metricsObject * @return */ public List<CouchDBMetric> constructMetricsList(JsonObject metricsObject) { // 1st level: Metric Category // 2nd level: Metric Name // 3rd level: MetricAggregationType List<CouchDBMetric> metricsList = Lists.newArrayList(); for (Entry<String, JsonElement> category : metricsObject.entrySet()) { JsonObject categoryMetrics = category.getValue().getAsJsonObject(); for (Entry<String, JsonElement> metric : categoryMetrics.entrySet()) { CouchDBMetric couchDBMetric = new CouchDBMetric(); couchDBMetric.setMetricCategory(category.getKey()); couchDBMetric.setMetricName(metric.getKey()); JsonObject jsonObject = metric.getValue().getAsJsonObject(); Map<MetricAggregationType, BigDecimal> values = Maps.newHashMap(); for (MetricAggregationType type : MetricAggregationType.values()) { if (!jsonObject.get(type.getAggregationType()).isJsonNull()) { BigDecimal metricValue = jsonObject.get(type.getAggregationType()).getAsBigDecimal(); logger.debug("Category:" + couchDBMetric.getMetricCategory() + " MetricName:" + couchDBMetric.getMetricName() + " " + type + ":" + metricValue); values.put(type, metricValue); } } couchDBMetric.setValues(values); metricsList.add(couchDBMetric); } } return metricsList; }
From source file:com.appdynamics.monitors.varnish.VarnishWrapper.java
License:Apache License
/** * Constructs the metrics hashmap by iterating over the JSON response retrieved from the /stats url * @param responseData the JSON response retrieved from hitting the /stats url * @return HashMap containing all metrics for Varnish * @throws Exception/*from w w w . jav a2 s . co m*/ */ private HashMap<String, Long> constructMetricsMap(JsonObject responseData) throws Exception { HashMap<String, Long> metrics = new HashMap<String, Long>(); Iterator iterator = responseData.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, JsonElement> entry = (Map.Entry<String, JsonElement>) iterator.next(); if (!entry.getValue().isJsonPrimitive()) { String metricName = entry.getKey(); JsonObject metricObject = entry.getValue().getAsJsonObject(); Long metricValue = metricObject.get("value").getAsLong(); metrics.put(metricName, metricValue); } } return metrics; }
From source file:com.arpnetworking.kairosdb.HistogramDataPointFactory.java
License:Apache License
@Override public DataPoint getDataPoint(final long timestamp, final JsonElement json) throws IOException { final TreeMap<Double, Integer> binValues = new TreeMap<>(); final JsonObject object = json.getAsJsonObject(); final double min = object.get("min").getAsDouble(); final double max = object.get("max").getAsDouble(); final double mean = object.get("mean").getAsDouble(); final double sum = object.get("sum").getAsDouble(); final JsonObject bins = object.get("bins").getAsJsonObject(); for (Map.Entry<String, JsonElement> entry : bins.entrySet()) { binValues.put(Double.parseDouble(entry.getKey()), entry.getValue().getAsInt()); }/*from ww w .ja v a2 s. c om*/ return new HistogramDataPointImpl(timestamp, 7, binValues, min, max, mean, sum); }
From source file:com.atlauncher.data.mojang.DownloadsTypeAdapter.java
License:Open Source License
@Override public Downloads deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { DownloadsItem artifact = null;//from w w w . jav a 2 s.c o m Map<String, DownloadsItem> classifiers = new HashMap<String, DownloadsItem>(); final JsonObject rootJsonObject = json.getAsJsonObject(); if (rootJsonObject.has("artifact")) { final JsonObject artifactObject = rootJsonObject.getAsJsonObject("artifact"); artifact = Gsons.DEFAULT_ALT.fromJson(artifactObject, DownloadsItem.class); } if (rootJsonObject.has("classifiers")) { final JsonObject classifiersObject = rootJsonObject.getAsJsonObject("classifiers"); Set<Entry<String, JsonElement>> entrySet = classifiersObject.entrySet(); for (Map.Entry<String, JsonElement> entry : entrySet) { classifiers.put(entry.getKey(), Gsons.DEFAULT_ALT.fromJson(entry.getValue().getAsJsonObject(), DownloadsItem.class)); } } return new Downloads(artifact, classifiers); }
From source file:com.azure.webapi.MobileServiceTableBase.java
License:Open Source License
/** * Patches the original entity with the one returned in the response after * executing the operation//from w w w . java 2 s . co m * * @param originalEntity * The original entity * @param newEntity * The entity obtained after executing the operation * @return */ protected JsonObject patchOriginalEntityWithResponseEntity(JsonObject originalEntity, JsonObject newEntity) { // Patch the object to return with the new values JsonObject patchedEntityJson = (JsonObject) new JsonParser().parse(originalEntity.toString()); for (Map.Entry<String, JsonElement> entry : newEntity.entrySet()) { patchedEntityJson.add(entry.getKey(), entry.getValue()); } return patchedEntityJson; }