class Nodes {

    public static int countOutgoing( NodeCursor nodeCursor, CursorFactory cursors )
    {
        if ( nodeCursor.isDense() )
        {
            try ( RelationshipGroupCursor group = cursors.allocateRelationshipGroupCursor() )
            {
                nodeCursor.relationships( group );
                int count = 0;
                while ( group.next() )
                {
                    count += group.outgoingCount() + group.loopCount();
                }
                return count;
            }
        }
        else
        {
            try ( RelationshipTraversalCursor traversal = cursors.allocateRelationshipTraversalCursor() )
            {
                int count = 0;
                nodeCursor.allRelationships( traversal );
                while ( traversal.next() )
                {
                    if ( traversal.sourceNodeReference() == nodeCursor.nodeReference() )
                    {
                        count++;
                    }
                }
                return count;
            }
        }
    }

    private  Nodes();

}