Format Java code to ONAP standard
[aai/search-data-service.git] / src / main / java / org / onap / aai / sa / searchdbabstraction / util / AggregationParsingUtil.java
index 93ee23e..def3f04 100644 (file)
@@ -29,73 +29,71 @@ import org.onap.aai.sa.searchdbabstraction.entity.AggregationBucket;
 import org.onap.aai.sa.searchdbabstraction.entity.AggregationResult;
 
 public class AggregationParsingUtil {
-  public static AggregationResult[] parseAggregationResults(JSONObject aggregations)
-    throws JsonProcessingException {
+    public static AggregationResult[] parseAggregationResults(JSONObject aggregations) throws JsonProcessingException {
 
-    // Obtain the set of aggregation names
-    Set keySet = aggregations.keySet();
-    AggregationResult[] aggResults = new AggregationResult[keySet.size()];
+        // Obtain the set of aggregation names
+        Set keySet = aggregations.keySet();
+        AggregationResult[] aggResults = new AggregationResult[keySet.size()];
 
-    int index = 0;
-    for (Iterator it = keySet.iterator(); it.hasNext(); ) {
-      String key = (String) it.next();
-      AggregationResult aggResult = new AggregationResult();
-      aggResult.setName(key);
+        int index = 0;
+        for (Iterator it = keySet.iterator(); it.hasNext();) {
+            String key = (String) it.next();
+            AggregationResult aggResult = new AggregationResult();
+            aggResult.setName(key);
 
-      JSONObject bucketsOrNested = (JSONObject) aggregations.get(key);
-      Object buckets = bucketsOrNested.get("buckets");
-      if (buckets == null) {
-        // we have a nested
-        Number count = (Number) bucketsOrNested.remove("doc_count");
-        aggResult.setCount(count);
-        AggregationResult[] nestedResults = parseAggregationResults(bucketsOrNested);
-        aggResult.setNestedAggregations(nestedResults);
-      } else {
-        AggregationBucket[] aggBuckets = parseAggregationBuckets((JSONArray) buckets);
-        aggResult.setBuckets(aggBuckets);
-      }
+            JSONObject bucketsOrNested = (JSONObject) aggregations.get(key);
+            Object buckets = bucketsOrNested.get("buckets");
+            if (buckets == null) {
+                // we have a nested
+                Number count = (Number) bucketsOrNested.remove("doc_count");
+                aggResult.setCount(count);
+                AggregationResult[] nestedResults = parseAggregationResults(bucketsOrNested);
+                aggResult.setNestedAggregations(nestedResults);
+            } else {
+                AggregationBucket[] aggBuckets = parseAggregationBuckets((JSONArray) buckets);
+                aggResult.setBuckets(aggBuckets);
+            }
 
-      aggResults[index] = aggResult;
-      index++;
-    }
+            aggResults[index] = aggResult;
+            index++;
+        }
 
-    return aggResults;
+        return aggResults;
 
-  }
+    }
 
-  private static AggregationBucket[] parseAggregationBuckets(JSONArray buckets)
-    throws JsonProcessingException {
-    AggregationBucket[] aggBuckets = new AggregationBucket[buckets.size()];
-    for (int i = 0; i < buckets.size(); i++) {
-      AggregationBucket aggBucket = new AggregationBucket();
-      JSONObject bucketContent = (JSONObject) buckets.get(i);
-      Object key = bucketContent.remove("key");
-      aggBucket.setKey(key);
-      Object formatted = bucketContent.remove("key_as_string");
-      if (formatted != null) {
-        aggBucket.setFormattedKey((String) formatted);
-      }
-      Object count = bucketContent.remove("doc_count");
-      if (count != null) {
-        aggBucket.setCount((Number) count);
-      }
-      bucketContent.remove("from");
-      bucketContent.remove("from_as_string");
-      bucketContent.remove("to");
-      bucketContent.remove("to_as_string");
+    private static AggregationBucket[] parseAggregationBuckets(JSONArray buckets) throws JsonProcessingException {
+        AggregationBucket[] aggBuckets = new AggregationBucket[buckets.size()];
+        for (int i = 0; i < buckets.size(); i++) {
+            AggregationBucket aggBucket = new AggregationBucket();
+            JSONObject bucketContent = (JSONObject) buckets.get(i);
+            Object key = bucketContent.remove("key");
+            aggBucket.setKey(key);
+            Object formatted = bucketContent.remove("key_as_string");
+            if (formatted != null) {
+                aggBucket.setFormattedKey((String) formatted);
+            }
+            Object count = bucketContent.remove("doc_count");
+            if (count != null) {
+                aggBucket.setCount((Number) count);
+            }
+            bucketContent.remove("from");
+            bucketContent.remove("from_as_string");
+            bucketContent.remove("to");
+            bucketContent.remove("to_as_string");
 
 
-      if (!bucketContent.entrySet().isEmpty()) {
-        // we have results from sub-aggregation
-        AggregationResult[] subResult = parseAggregationResults(bucketContent);
-        if (subResult != null) {
-          aggBucket.setSubAggregationResult(subResult);
+            if (!bucketContent.entrySet().isEmpty()) {
+                // we have results from sub-aggregation
+                AggregationResult[] subResult = parseAggregationResults(bucketContent);
+                if (subResult != null) {
+                    aggBucket.setSubAggregationResult(subResult);
+                }
+            }
+            aggBuckets[i] = aggBucket;
         }
-      }
-      aggBuckets[i] = aggBucket;
-    }
 
-    return aggBuckets;
-  }
+        return aggBuckets;
+    }
 
 }