package example;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Label;
import org.neo4j.logging.Log;
import org.neo4j.procedure.*;

import java.util.stream.Stream;

public class Degree {
    @Context
    public GraphDatabaseService db;

    @Context
    public Log log;

//    private static final Map<String, >

    @Procedure(value = "example.degree", mode = Mode.READ)
    @Description("Calculate degree of vertex")
    public Stream<DegreeResults> degree(@Name("label") String label) {
        String index = "label-" + label;

        if (!db.index().existsForNodes(index)) {
            log.debug("Skipping since index does not exist: `%s`", index);
            return Stream.empty();
        }

        Label ind = Label.label(label);

        return db.findNodes(ind).stream().map(DegreeResults::new);
    }


    public class DegreeResults {
        public final Integer degree;
        public final Long nodes;

        public DegreeResults(Integer degree, Long nodes) {
            this.degree = degree;
            this.nodes = nodes;
        }

    }
}

@@ -111,51 +111,176 @@
 o4j.
-logging.Log;%0Aimport org.neo4j.procedure.*;%0A
+graphdb.Node;%0Aimport org.neo4j.graphdb.ResourceIterator;%0Aimport org.neo4j.logging.Log;%0Aimport org.neo4j.procedure.*;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;
 %0Aimp
@@ -419,50 +419,8 @@
 g;%0A%0A
-//    private static final Map%3CString, %3E%0A%0A
     
@@ -604,41 +604,39 @@
     
-String
+Label
  ind
-ex
  = 
-%22label-%22 + 
+Label.label(
 label
+)
 ;
-%0A
 %0A   
@@ -644,45 +644,84 @@
     
-if (!
+ResourceIterator%3CNode%3E nodes = 
 db.
+f
 ind
-ex().existsForNodes(index)
+Nodes(ind);%0A%0A        if (nodes == null
 ) %7B%0A
@@ -787,21 +787,21 @@
  %60%25s%60%22, 
-index
+label
 );%0A     
@@ -854,113 +854,291 @@
    L
-abel ind = Label.label(label);%0A%0A        return db.findNodes(ind).stream().map(DegreeResults::new);%0A    %7D%0A
+ist%3CDegreeResults%3E a = new ArrayList%3C%3E();%0A%0A        while(nodes.hasNext()) %7B%0A            final Node recordNode = nodes.next();%0A            DegreeResults t = new DegreeResults(recordNode.getDegree(),recordNode.getId());%0A            a.add(t);%0A        %7D%0A%0A        return a.stream();%0A    %7D
 %0A%0A  

Fix types mismatch at example.degree