AAI-1523 Batch reformat aai-core
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / serialization / queryformats / Count.java
index 053c8de..8ee4e3a 100644 (file)
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aai.serialization.queryformats;
 
 import com.google.gson.JsonObject;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
 import org.apache.tinkerpop.gremlin.process.traversal.Path;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -28,53 +34,48 @@ import org.onap.aai.db.props.AAIProperties;
 import org.onap.aai.serialization.queryformats.exceptions.AAIFormatQueryResultFormatNotSupported;
 import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexException;
 
-import java.util.List;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
 public class Count implements FormatMapper {
 
-       @Override
-       public Optional<JsonObject> formatObject(Object o) throws AAIFormatVertexException, AAIFormatQueryResultFormatNotSupported {
-               @SuppressWarnings("unchecked")
-               List<Object> list = (List<Object>) o;
-               
-               final JsonObject countResult = new JsonObject();
-               
-               list.stream().map(this::getCount)
-               .filter( Optional::isPresent )
-               .map(Optional::get)
-               .collect( Collectors.toConcurrentMap( Pair::getValue0, Pair::getValue1, Long::sum ) )
-               .forEach( (k,v) -> countResult.addProperty(k, v) );
-               
-               return Optional.of(countResult);
-       }
-
-       @Override
-       public int parallelThreshold() {
-               return 20;
-       }
-       
-       private Optional<Pair<String, Long>> getCount(Object o){
-               
-               Pair<String, Long> pair = null;
-               
-               if (o instanceof Vertex) {
-                       Vertex v = (Vertex) o;
-                       pair =  Pair.with(v.property(AAIProperties.NODE_TYPE).value().toString(), 1L);
-               } else if (o instanceof Tree) {
-                       pair = Pair.with("trees", 1L);
-               } else if (o instanceof Path) {
-                       pair = Pair.with("paths", 1L);
-               } else if (o instanceof Long) {
-                       pair = Pair.with("count", (Long)o);
-               }
-               
-               if (pair == null) {
-                       return Optional.<Pair<String, Long>>empty();
-               }
-               
-               return Optional.<Pair<String, Long>>of(pair);
-       }
+    @Override
+    public Optional<JsonObject> formatObject(Object o)
+            throws AAIFormatVertexException, AAIFormatQueryResultFormatNotSupported {
+        @SuppressWarnings("unchecked")
+        List<Object> list = (List<Object>) o;
+
+        final JsonObject countResult = new JsonObject();
+
+        list.stream().map(this::getCount).filter(Optional::isPresent).map(Optional::get)
+                .collect(Collectors.toConcurrentMap(Pair::getValue0, Pair::getValue1, Long::sum))
+                .forEach((k, v) -> countResult.addProperty(k, v));
+
+        return Optional.of(countResult);
+    }
+
+    @Override
+    public int parallelThreshold() {
+        return 20;
+    }
+
+    private Optional<Pair<String, Long>> getCount(Object o) {
+
+        Pair<String, Long> pair = null;
+
+        if (o instanceof Vertex) {
+            Vertex v = (Vertex) o;
+            pair = Pair.with(v.property(AAIProperties.NODE_TYPE).value().toString(), 1L);
+        } else if (o instanceof Tree) {
+            pair = Pair.with("trees", 1L);
+        } else if (o instanceof Path) {
+            pair = Pair.with("paths", 1L);
+        } else if (o instanceof Long) {
+            pair = Pair.with("count", (Long) o);
+        }
+
+        if (pair == null) {
+            return Optional.<Pair<String, Long>>empty();
+        }
+
+        return Optional.<Pair<String, Long>>of(pair);
+    }
 
 }