{"action":"created","comment":{"url":"https://api.github.com/repos/arhangeldim/messenger/pulls/comments/58307373","id":58307373,"diff_hunk":"@@ -24,27 +31,70 @@ public BeanVertex addVertex(Bean value) {\n      * @param from из какой вершины\n      * @param to в какую вершину\n      */\n-    public void addEdge(BeanVertex from ,BeanVertex to) {\n+    public void addEdge(BeanVertex from, BeanVertex to) {\n+        if (from == null || to == null) {\n+            throw new NullPointerException(\"null vertex\");\n+        }\n+        if (!isConnected(from, to)) {\n+            vertices.get(from).add(to);\n+        }\n     }\n \n     /**\n      * Проверяем, связаны ли вершины\n      */\n     public boolean isConnected(BeanVertex v1, BeanVertex v2) {\n-        return false;\n+        return getLinked(v1).contains(v2);\n     }\n \n     /**\n      * Получить список вершин, с которыми связана vertex\n      */\n     public List<BeanVertex> getLinked(BeanVertex vertex) {\n-        return null;\n+        return vertices.get(vertex);\n     }\n \n     /**\n      * Количество вершин в графе\n      */\n     public int size() {\n-        return 0;\n+        return vertices.size();\n     }\n+\n+    /**\n+     * Топологическая сортировка\n+     * Предполагаем, что все верщины до начала сортировки белые\n+     * @return null, если в графе есть цикл, иначе массив отсортированных вершин\n+     */\n+    public List<BeanVertex> topSort() {\n+        List<BeanVertex> sortedList = new ArrayList<>();\n+        Set<BeanVertex> vertexSet = vertices.keySet();\n+        for (BeanVertex vertex : vertexSet) {\n+            if (!dfs(vertex, sortedList)) {\n+                return null;\n+            }\n+        }\n+        return sortedList;\n+    }\n+\n+    /**\n+     * Обход дерева в глубину, с проверкой на цикличность\n+      * @param vertex вершина, с которой начинаем обход\n+     * @return true, если все успешно, false, если встретился цикл\n+     */\n+    public boolean dfs(BeanVertex vertex, List<BeanVertex> sortedList) {\n+        vertex.setColor(BeanVertex.Color.GRAY);\n+        for (BeanVertex v : getLinked(vertex)) {\n+            if (v.getColor() == BeanVertex.Color.GRAY) {\n+                return false;","path":"src/main/java/arhangel/dim/container/BeanGraph.java","position":88,"original_position":88,"commit_id":"0d58ccc4f790e579024dc6882bd099b60943e56a","original_commit_id":"0d58ccc4f790e579024dc6882bd099b60943e56a","user":{"login":"arhangeldim","id":1112038,"avatar_url":"https://avatars.githubusercontent.com/u/1112038?v=3","gravatar_id":"","url":"https://api.github.com/users/arhangeldim","html_url":"https://github.com/arhangeldim","followers_url":"https://api.github.com/users/arhangeldim/followers","following_url":"https://api.github.com/users/arhangeldim/following{/other_user}","gists_url":"https://api.github.com/users/arhangeldim/gists{/gist_id}","starred_url":"https://api.github.com/users/arhangeldim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arhangeldim/subscriptions","organizations_url":"https://api.github.com/users/arhangeldim/orgs","repos_url":"https://api.github.com/users/arhangeldim/repos","events_url":"https://api.github.com/users/arhangeldim/events{/privacy}","received_events_url":"https://api.github.com/users/arhangeldim/received_events","type":"User","site_admin":false},"body":"Если встретился цикл, то кидаем CycleReferenceException","created_at":"2016-04-03T09:32:20Z","updated_at":"2016-04-03T09:32:20Z","html_url":"https://github.com/arhangeldim/messenger/pull/29#discussion_r58307373","pull_request_url":"https://api.github.com/repos/arhangeldim/messenger/pulls/29","_links":{"self":{"href":"https://api.github.com/repos/arhangeldim/messenger/pulls/comments/58307373"},"html":{"href":"https://github.com/arhangeldim/messenger/pull/29#discussion_r58307373"},"pull_request":{"href":"https://api.github.com/repos/arhangeldim/messenger/pulls/29"}}},"pull_request":{"url":"https://api.github.com/repos/arhangeldim/messenger/pulls/29","id":64167600,"html_url":"https://github.com/arhangeldim/messenger/pull/29","diff_url":"https://github.com/arhangeldim/messenger/pull/29.diff","patch_url":"https://github.com/arhangeldim/messenger/pull/29.patch","issue_url":"https://api.github.com/repos/arhangeldim/messenger/issues/29","number":29,"state":"open","locked":false,"title":"Tasks 1-4","user":{"login":"PodoltsevaOlga","id":5609606,"avatar_url":"https://avatars.githubusercontent.com/u/5609606?v=3","gravatar_id":"","url":"https://api.github.com/users/PodoltsevaOlga","html_url":"https://github.com/PodoltsevaOlga","followers_url":"https://api.github.com/users/PodoltsevaOlga/followers","following_url":"https://api.github.com/users/PodoltsevaOlga/following{/other_user}","gists_url":"https://api.github.com/users/PodoltsevaOlga/gists{/gist_id}","starred_url":"https://api.github.com/users/PodoltsevaOlga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PodoltsevaOlga/subscriptions","organizations_url":"https://api.github.com/users/PodoltsevaOlga/orgs","repos_url":"https://api.github.com/users/PodoltsevaOlga/repos","events_url":"https://api.github.com/users/PodoltsevaOlga/events{/privacy}","received_events_url":"https://api.github.com/users/PodoltsevaOlga/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-03-25T14:32:38Z","updated_at":"2016-04-03T09:32:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9f84e98fa1eed18508d0cfc353a5b7615566c26a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/arhangeldim/messenger/pulls/29/commits","review_comments_url":"https://api.github.com/repos/arhangeldim/messenger/pulls/29/comments","review_comment_url":"https://api.github.com/repos/arhangeldim/messenger/pulls/comments{/number}","comments_url":"https://api.github.com/repos/arhangeldim/messenger/issues/29/comments","statuses_url":"https://api.github.com/repos/arhangeldim/messenger/statuses/0d58ccc4f790e579024dc6882bd099b60943e56a","head":{"label":"PodoltsevaOlga:PodoltsevaOlga-Container","ref":"PodoltsevaOlga-Container","sha":"0d58ccc4f790e579024dc6882bd099b60943e56a","user":{"login":"PodoltsevaOlga","id":5609606,"avatar_url":"https://avatars.githubusercontent.com/u/5609606?v=3","gravatar_id":"","url":"https://api.github.com/users/PodoltsevaOlga","html_url":"https://github.com/PodoltsevaOlga","followers_url":"https://api.github.com/users/PodoltsevaOlga/followers","following_url":"https://api.github.com/users/PodoltsevaOlga/following{/other_user}","gists_url":"https://api.github.com/users/PodoltsevaOlga/gists{/gist_id}","starred_url":"https://api.github.com/users/PodoltsevaOlga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PodoltsevaOlga/subscriptions","organizations_url":"https://api.github.com/users/PodoltsevaOlga/orgs","repos_url":"https://api.github.com/users/PodoltsevaOlga/repos","events_url":"https://api.github.com/users/PodoltsevaOlga/events{/privacy}","received_events_url":"https://api.github.com/users/PodoltsevaOlga/received_events","type":"User","site_admin":false},"repo":{"id":54674635,"name":"messenger","full_name":"PodoltsevaOlga/messenger","owner":{"login":"PodoltsevaOlga","id":5609606,"avatar_url":"https://avatars.githubusercontent.com/u/5609606?v=3","gravatar_id":"","url":"https://api.github.com/users/PodoltsevaOlga","html_url":"https://github.com/PodoltsevaOlga","followers_url":"https://api.github.com/users/PodoltsevaOlga/followers","following_url":"https://api.github.com/users/PodoltsevaOlga/following{/other_user}","gists_url":"https://api.github.com/users/PodoltsevaOlga/gists{/gist_id}","starred_url":"https://api.github.com/users/PodoltsevaOlga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PodoltsevaOlga/subscriptions","organizations_url":"https://api.github.com/users/PodoltsevaOlga/orgs","repos_url":"https://api.github.com/users/PodoltsevaOlga/repos","events_url":"https://api.github.com/users/PodoltsevaOlga/events{/privacy}","received_events_url":"https://api.github.com/users/PodoltsevaOlga/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/PodoltsevaOlga/messenger","description":"","fork":true,"url":"https://api.github.com/repos/PodoltsevaOlga/messenger","forks_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/forks","keys_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/teams","hooks_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/hooks","issue_events_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/issues/events{/number}","events_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/events","assignees_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/assignees{/user}","branches_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/branches{/branch}","tags_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/tags","blobs_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/git/refs{/sha}","trees_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/statuses/{sha}","languages_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/languages","stargazers_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/stargazers","contributors_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/contributors","subscribers_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/subscribers","subscription_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/subscription","commits_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/commits{/sha}","git_commits_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/git/commits{/sha}","comments_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/comments{/number}","issue_comment_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/issues/comments{/number}","contents_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/contents/{+path}","compare_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/merges","archive_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/downloads","issues_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/issues{/number}","pulls_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/pulls{/number}","milestones_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/milestones{/number}","notifications_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/labels{/name}","releases_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/releases{/id}","deployments_url":"https://api.github.com/repos/PodoltsevaOlga/messenger/deployments","created_at":"2016-03-24T21:13:46Z","updated_at":"2016-03-24T21:13:47Z","pushed_at":"2016-03-25T14:30:24Z","git_url":"git://github.com/PodoltsevaOlga/messenger.git","ssh_url":"git@github.com:PodoltsevaOlga/messenger.git","clone_url":"https://github.com/PodoltsevaOlga/messenger.git","svn_url":"https://github.com/PodoltsevaOlga/messenger","homepage":null,"size":575,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"arhangeldim:master","ref":"master","sha":"5f60fbac2505448a8d2f48ba355bc522716dc0bf","user":{"login":"arhangeldim","id":1112038,"avatar_url":"https://avatars.githubusercontent.com/u/1112038?v=3","gravatar_id":"","url":"https://api.github.com/users/arhangeldim","html_url":"https://github.com/arhangeldim","followers_url":"https://api.github.com/users/arhangeldim/followers","following_url":"https://api.github.com/users/arhangeldim/following{/other_user}","gists_url":"https://api.github.com/users/arhangeldim/gists{/gist_id}","starred_url":"https://api.github.com/users/arhangeldim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arhangeldim/subscriptions","organizations_url":"https://api.github.com/users/arhangeldim/orgs","repos_url":"https://api.github.com/users/arhangeldim/repos","events_url":"https://api.github.com/users/arhangeldim/events{/privacy}","received_events_url":"https://api.github.com/users/arhangeldim/received_events","type":"User","site_admin":false},"repo":{"id":52207105,"name":"messenger","full_name":"arhangeldim/messenger","owner":{"login":"arhangeldim","id":1112038,"avatar_url":"https://avatars.githubusercontent.com/u/1112038?v=3","gravatar_id":"","url":"https://api.github.com/users/arhangeldim","html_url":"https://github.com/arhangeldim","followers_url":"https://api.github.com/users/arhangeldim/followers","following_url":"https://api.github.com/users/arhangeldim/following{/other_user}","gists_url":"https://api.github.com/users/arhangeldim/gists{/gist_id}","starred_url":"https://api.github.com/users/arhangeldim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arhangeldim/subscriptions","organizations_url":"https://api.github.com/users/arhangeldim/orgs","repos_url":"https://api.github.com/users/arhangeldim/repos","events_url":"https://api.github.com/users/arhangeldim/events{/privacy}","received_events_url":"https://api.github.com/users/arhangeldim/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/arhangeldim/messenger","description":"","fork":false,"url":"https://api.github.com/repos/arhangeldim/messenger","forks_url":"https://api.github.com/repos/arhangeldim/messenger/forks","keys_url":"https://api.github.com/repos/arhangeldim/messenger/keys{/key_id}","collaborators_url":"https://api.github.com/repos/arhangeldim/messenger/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/arhangeldim/messenger/teams","hooks_url":"https://api.github.com/repos/arhangeldim/messenger/hooks","issue_events_url":"https://api.github.com/repos/arhangeldim/messenger/issues/events{/number}","events_url":"https://api.github.com/repos/arhangeldim/messenger/events","assignees_url":"https://api.github.com/repos/arhangeldim/messenger/assignees{/user}","branches_url":"https://api.github.com/repos/arhangeldim/messenger/branches{/branch}","tags_url":"https://api.github.com/repos/arhangeldim/messenger/tags","blobs_url":"https://api.github.com/repos/arhangeldim/messenger/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/arhangeldim/messenger/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/arhangeldim/messenger/git/refs{/sha}","trees_url":"https://api.github.com/repos/arhangeldim/messenger/git/trees{/sha}","statuses_url":"https://api.github.com/repos/arhangeldim/messenger/statuses/{sha}","languages_url":"https://api.github.com/repos/arhangeldim/messenger/languages","stargazers_url":"https://api.github.com/repos/arhangeldim/messenger/stargazers","contributors_url":"https://api.github.com/repos/arhangeldim/messenger/contributors","subscribers_url":"https://api.github.com/repos/arhangeldim/messenger/subscribers","subscription_url":"https://api.github.com/repos/arhangeldim/messenger/subscription","commits_url":"https://api.github.com/repos/arhangeldim/messenger/commits{/sha}","git_commits_url":"https://api.github.com/repos/arhangeldim/messenger/git/commits{/sha}","comments_url":"https://api.github.com/repos/arhangeldim/messenger/comments{/number}","issue_comment_url":"https://api.github.com/repos/arhangeldim/messenger/issues/comments{/number}","contents_url":"https://api.github.com/repos/arhangeldim/messenger/contents/{+path}","compare_url":"https://api.github.com/repos/arhangeldim/messenger/compare/{base}...{head}","merges_url":"https://api.github.com/repos/arhangeldim/messenger/merges","archive_url":"https://api.github.com/repos/arhangeldim/messenger/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/arhangeldim/messenger/downloads","issues_url":"https://api.github.com/repos/arhangeldim/messenger/issues{/number}","pulls_url":"https://api.github.com/repos/arhangeldim/messenger/pulls{/number}","milestones_url":"https://api.github.com/repos/arhangeldim/messenger/milestones{/number}","notifications_url":"https://api.github.com/repos/arhangeldim/messenger/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/arhangeldim/messenger/labels{/name}","releases_url":"https://api.github.com/repos/arhangeldim/messenger/releases{/id}","deployments_url":"https://api.github.com/repos/arhangeldim/messenger/deployments","created_at":"2016-02-21T13:11:43Z","updated_at":"2016-03-20T20:11:17Z","pushed_at":"2016-03-29T19:49:55Z","git_url":"git://github.com/arhangeldim/messenger.git","ssh_url":"git@github.com:arhangeldim/messenger.git","clone_url":"https://github.com/arhangeldim/messenger.git","svn_url":"https://github.com/arhangeldim/messenger","homepage":null,"size":901,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":38,"mirror_url":null,"open_issues_count":34,"forks":38,"open_issues":34,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/arhangeldim/messenger/pulls/29"},"html":{"href":"https://github.com/arhangeldim/messenger/pull/29"},"issue":{"href":"https://api.github.com/repos/arhangeldim/messenger/issues/29"},"comments":{"href":"https://api.github.com/repos/arhangeldim/messenger/issues/29/comments"},"review_comments":{"href":"https://api.github.com/repos/arhangeldim/messenger/pulls/29/comments"},"review_comment":{"href":"https://api.github.com/repos/arhangeldim/messenger/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/arhangeldim/messenger/pulls/29/commits"},"statuses":{"href":"https://api.github.com/repos/arhangeldim/messenger/statuses/0d58ccc4f790e579024dc6882bd099b60943e56a"}}}}