{"action":"created","comment":{"url":"https://api.github.com/repos/svloyso/java_homeworks/pulls/comments/55127345","id":55127345,"diff_hunk":"@@ -0,0 +1,104 @@\n+package sp;\n+\n+import java.util.AbstractMap;\n+import java.util.HashMap;\n+\n+public class TrieImpl implements Trie {\n+\n+    public TrieImpl() {\n+        childs = new HashMap<Character, TrieImpl>();\n+        endOfWord = false;\n+    }\n+\n+    public int size() {\n+        return size;\n+    }\n+\n+    public boolean add(String element) {\n+        return add(element, 0);\n+    }\n+\n+    public boolean contains(String element) {\n+        return contains(element, 0);\n+    }\n+\n+    public boolean remove(String element) {\n+        return remove(element, 0);\n+    }\n+\n+    public int howManyStartsWithPrefix(String prefix) {\n+        return howManyStartsWithPrefix(prefix, 0);\n+    }\n+\n+    private boolean add(String element, int i) {\n+        if (element.length() == i) {\n+            if (endOfWord) {\n+                return false;\n+            } else {\n+                endOfWord = true;\n+            }\n+        } else {\n+            Character head = element.charAt(i);\n+            TrieImpl child;\n+            if (childs.containsKey(head)) {\n+                child = childs.get(head);\n+            } else {\n+                child = new TrieImpl();\n+                childs.put(head, child);\n+            }\n+            child.add(element, i + 1);\n+        }\n+        size += 1;\n+        return true;\n+    }\n+\n+    private boolean contains(String element, int i) {\n+        if (element.length() == i) {\n+            return endOfWord;\n+        } \n+        Character head = element.charAt(i);\n+        if (childs.containsKey(head)) {\n+            return childs.get(head).contains(element, i + 1);\n+        }\n+        return false;\n+    }\n+\n+    private boolean remove(String element, int i) {\n+        if (element.length() == i) {\n+            if (endOfWord) {\n+                size -= 1;\n+                endOfWord = false;\n+                return true;\n+            }\n+            return false;\n+        }\n+        Character head = element.charAt(i);\n+        if (childs.containsKey(head)) {\n+            TrieImpl child = childs.get(head);\n+            boolean removed = child.remove(element, i + 1);\n+            if (!removed) {\n+                return false;\n+            }\n+            size -= 1;\n+            return true;\n+        }\n+        return false;\n+    }\n+\n+    private int howManyStartsWithPrefix(String prefix, int i) {\n+        if (prefix.length() == i) {\n+            return size;\n+        }\n+        Character head = prefix.charAt(i);\n+        if (childs.containsKey(head)) {\n+            TrieImpl child = childs.get(head);\n+            return child.howManyStartsWithPrefix(prefix, i + 1);\n+        }\n+        return 0;\n+    }\n+\n+\n+    private boolean endOfWord;\n+    private int size;\n+    private AbstractMap<Character, TrieImpl> childs;","path":"hw_1/sp/TrieImpl.java","position":103,"original_position":103,"commit_id":"16444671db25bff85955e94f22c35724edc717ec","original_commit_id":"16444671db25bff85955e94f22c35724edc717ec","user":{"login":"sproshev","id":4990763,"avatar_url":"https://avatars.githubusercontent.com/u/4990763?v=3","gravatar_id":"","url":"https://api.github.com/users/sproshev","html_url":"https://github.com/sproshev","followers_url":"https://api.github.com/users/sproshev/followers","following_url":"https://api.github.com/users/sproshev/following{/other_user}","gists_url":"https://api.github.com/users/sproshev/gists{/gist_id}","starred_url":"https://api.github.com/users/sproshev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sproshev/subscriptions","organizations_url":"https://api.github.com/users/sproshev/orgs","repos_url":"https://api.github.com/users/sproshev/repos","events_url":"https://api.github.com/users/sproshev/events{/privacy}","received_events_url":"https://api.github.com/users/sproshev/received_events","type":"User","site_admin":false},"body":"final, children","created_at":"2016-03-05T20:23:09Z","updated_at":"2016-03-05T20:23:09Z","html_url":"https://github.com/svloyso/java_homeworks/pull/1#discussion_r55127345","pull_request_url":"https://api.github.com/repos/svloyso/java_homeworks/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/svloyso/java_homeworks/pulls/comments/55127345"},"html":{"href":"https://github.com/svloyso/java_homeworks/pull/1#discussion_r55127345"},"pull_request":{"href":"https://api.github.com/repos/svloyso/java_homeworks/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/svloyso/java_homeworks/pulls/1","id":61810593,"html_url":"https://github.com/svloyso/java_homeworks/pull/1","diff_url":"https://github.com/svloyso/java_homeworks/pull/1.diff","patch_url":"https://github.com/svloyso/java_homeworks/pull/1.patch","issue_url":"https://api.github.com/repos/svloyso/java_homeworks/issues/1","number":1,"state":"open","locked":false,"title":"Домашняя работа №1","user":{"login":"svloyso","id":3002066,"avatar_url":"https://avatars.githubusercontent.com/u/3002066?v=3","gravatar_id":"","url":"https://api.github.com/users/svloyso","html_url":"https://github.com/svloyso","followers_url":"https://api.github.com/users/svloyso/followers","following_url":"https://api.github.com/users/svloyso/following{/other_user}","gists_url":"https://api.github.com/users/svloyso/gists{/gist_id}","starred_url":"https://api.github.com/users/svloyso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/svloyso/subscriptions","organizations_url":"https://api.github.com/users/svloyso/orgs","repos_url":"https://api.github.com/users/svloyso/repos","events_url":"https://api.github.com/users/svloyso/events{/privacy}","received_events_url":"https://api.github.com/users/svloyso/received_events","type":"User","site_admin":false},"body":"@sproshev\r\n","created_at":"2016-03-05T12:17:33Z","updated_at":"2016-03-05T20:23:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"600406bd252d54bf3b8f212d57283fa4dad46791","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/svloyso/java_homeworks/pulls/1/commits","review_comments_url":"https://api.github.com/repos/svloyso/java_homeworks/pulls/1/comments","review_comment_url":"https://api.github.com/repos/svloyso/java_homeworks/pulls/comments{/number}","comments_url":"https://api.github.com/repos/svloyso/java_homeworks/issues/1/comments","statuses_url":"https://api.github.com/repos/svloyso/java_homeworks/statuses/16444671db25bff85955e94f22c35724edc717ec","head":{"label":"svloyso:hw_01","ref":"hw_01","sha":"16444671db25bff85955e94f22c35724edc717ec","user":{"login":"svloyso","id":3002066,"avatar_url":"https://avatars.githubusercontent.com/u/3002066?v=3","gravatar_id":"","url":"https://api.github.com/users/svloyso","html_url":"https://github.com/svloyso","followers_url":"https://api.github.com/users/svloyso/followers","following_url":"https://api.github.com/users/svloyso/following{/other_user}","gists_url":"https://api.github.com/users/svloyso/gists{/gist_id}","starred_url":"https://api.github.com/users/svloyso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/svloyso/subscriptions","organizations_url":"https://api.github.com/users/svloyso/orgs","repos_url":"https://api.github.com/users/svloyso/repos","events_url":"https://api.github.com/users/svloyso/events{/privacy}","received_events_url":"https://api.github.com/users/svloyso/received_events","type":"User","site_admin":false},"repo":{"id":53199780,"name":"java_homeworks","full_name":"svloyso/java_homeworks","owner":{"login":"svloyso","id":3002066,"avatar_url":"https://avatars.githubusercontent.com/u/3002066?v=3","gravatar_id":"","url":"https://api.github.com/users/svloyso","html_url":"https://github.com/svloyso","followers_url":"https://api.github.com/users/svloyso/followers","following_url":"https://api.github.com/users/svloyso/following{/other_user}","gists_url":"https://api.github.com/users/svloyso/gists{/gist_id}","starred_url":"https://api.github.com/users/svloyso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/svloyso/subscriptions","organizations_url":"https://api.github.com/users/svloyso/orgs","repos_url":"https://api.github.com/users/svloyso/repos","events_url":"https://api.github.com/users/svloyso/events{/privacy}","received_events_url":"https://api.github.com/users/svloyso/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/svloyso/java_homeworks","description":"","fork":false,"url":"https://api.github.com/repos/svloyso/java_homeworks","forks_url":"https://api.github.com/repos/svloyso/java_homeworks/forks","keys_url":"https://api.github.com/repos/svloyso/java_homeworks/keys{/key_id}","collaborators_url":"https://api.github.com/repos/svloyso/java_homeworks/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/svloyso/java_homeworks/teams","hooks_url":"https://api.github.com/repos/svloyso/java_homeworks/hooks","issue_events_url":"https://api.github.com/repos/svloyso/java_homeworks/issues/events{/number}","events_url":"https://api.github.com/repos/svloyso/java_homeworks/events","assignees_url":"https://api.github.com/repos/svloyso/java_homeworks/assignees{/user}","branches_url":"https://api.github.com/repos/svloyso/java_homeworks/branches{/branch}","tags_url":"https://api.github.com/repos/svloyso/java_homeworks/tags","blobs_url":"https://api.github.com/repos/svloyso/java_homeworks/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/svloyso/java_homeworks/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/svloyso/java_homeworks/git/refs{/sha}","trees_url":"https://api.github.com/repos/svloyso/java_homeworks/git/trees{/sha}","statuses_url":"https://api.github.com/repos/svloyso/java_homeworks/statuses/{sha}","languages_url":"https://api.github.com/repos/svloyso/java_homeworks/languages","stargazers_url":"https://api.github.com/repos/svloyso/java_homeworks/stargazers","contributors_url":"https://api.github.com/repos/svloyso/java_homeworks/contributors","subscribers_url":"https://api.github.com/repos/svloyso/java_homeworks/subscribers","subscription_url":"https://api.github.com/repos/svloyso/java_homeworks/subscription","commits_url":"https://api.github.com/repos/svloyso/java_homeworks/commits{/sha}","git_commits_url":"https://api.github.com/repos/svloyso/java_homeworks/git/commits{/sha}","comments_url":"https://api.github.com/repos/svloyso/java_homeworks/comments{/number}","issue_comment_url":"https://api.github.com/repos/svloyso/java_homeworks/issues/comments{/number}","contents_url":"https://api.github.com/repos/svloyso/java_homeworks/contents/{+path}","compare_url":"https://api.github.com/repos/svloyso/java_homeworks/compare/{base}...{head}","merges_url":"https://api.github.com/repos/svloyso/java_homeworks/merges","archive_url":"https://api.github.com/repos/svloyso/java_homeworks/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/svloyso/java_homeworks/downloads","issues_url":"https://api.github.com/repos/svloyso/java_homeworks/issues{/number}","pulls_url":"https://api.github.com/repos/svloyso/java_homeworks/pulls{/number}","milestones_url":"https://api.github.com/repos/svloyso/java_homeworks/milestones{/number}","notifications_url":"https://api.github.com/repos/svloyso/java_homeworks/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/svloyso/java_homeworks/labels{/name}","releases_url":"https://api.github.com/repos/svloyso/java_homeworks/releases{/id}","deployments_url":"https://api.github.com/repos/svloyso/java_homeworks/deployments","created_at":"2016-03-05T12:13:04Z","updated_at":"2016-03-05T12:13:04Z","pushed_at":"2016-03-05T12:17:33Z","git_url":"git://github.com/svloyso/java_homeworks.git","ssh_url":"git@github.com:svloyso/java_homeworks.git","clone_url":"https://github.com/svloyso/java_homeworks.git","svn_url":"https://github.com/svloyso/java_homeworks","homepage":null,"size":1,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"svloyso:master","ref":"master","sha":"0cb3be7c77c3a8eb984fb26d717c553f4855e28f","user":{"login":"svloyso","id":3002066,"avatar_url":"https://avatars.githubusercontent.com/u/3002066?v=3","gravatar_id":"","url":"https://api.github.com/users/svloyso","html_url":"https://github.com/svloyso","followers_url":"https://api.github.com/users/svloyso/followers","following_url":"https://api.github.com/users/svloyso/following{/other_user}","gists_url":"https://api.github.com/users/svloyso/gists{/gist_id}","starred_url":"https://api.github.com/users/svloyso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/svloyso/subscriptions","organizations_url":"https://api.github.com/users/svloyso/orgs","repos_url":"https://api.github.com/users/svloyso/repos","events_url":"https://api.github.com/users/svloyso/events{/privacy}","received_events_url":"https://api.github.com/users/svloyso/received_events","type":"User","site_admin":false},"repo":{"id":53199780,"name":"java_homeworks","full_name":"svloyso/java_homeworks","owner":{"login":"svloyso","id":3002066,"avatar_url":"https://avatars.githubusercontent.com/u/3002066?v=3","gravatar_id":"","url":"https://api.github.com/users/svloyso","html_url":"https://github.com/svloyso","followers_url":"https://api.github.com/users/svloyso/followers","following_url":"https://api.github.com/users/svloyso/following{/other_user}","gists_url":"https://api.github.com/users/svloyso/gists{/gist_id}","starred_url":"https://api.github.com/users/svloyso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/svloyso/subscriptions","organizations_url":"https://api.github.com/users/svloyso/orgs","repos_url":"https://api.github.com/users/svloyso/repos","events_url":"https://api.github.com/users/svloyso/events{/privacy}","received_events_url":"https://api.github.com/users/svloyso/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/svloyso/java_homeworks","description":"","fork":false,"url":"https://api.github.com/repos/svloyso/java_homeworks","forks_url":"https://api.github.com/repos/svloyso/java_homeworks/forks","keys_url":"https://api.github.com/repos/svloyso/java_homeworks/keys{/key_id}","collaborators_url":"https://api.github.com/repos/svloyso/java_homeworks/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/svloyso/java_homeworks/teams","hooks_url":"https://api.github.com/repos/svloyso/java_homeworks/hooks","issue_events_url":"https://api.github.com/repos/svloyso/java_homeworks/issues/events{/number}","events_url":"https://api.github.com/repos/svloyso/java_homeworks/events","assignees_url":"https://api.github.com/repos/svloyso/java_homeworks/assignees{/user}","branches_url":"https://api.github.com/repos/svloyso/java_homeworks/branches{/branch}","tags_url":"https://api.github.com/repos/svloyso/java_homeworks/tags","blobs_url":"https://api.github.com/repos/svloyso/java_homeworks/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/svloyso/java_homeworks/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/svloyso/java_homeworks/git/refs{/sha}","trees_url":"https://api.github.com/repos/svloyso/java_homeworks/git/trees{/sha}","statuses_url":"https://api.github.com/repos/svloyso/java_homeworks/statuses/{sha}","languages_url":"https://api.github.com/repos/svloyso/java_homeworks/languages","stargazers_url":"https://api.github.com/repos/svloyso/java_homeworks/stargazers","contributors_url":"https://api.github.com/repos/svloyso/java_homeworks/contributors","subscribers_url":"https://api.github.com/repos/svloyso/java_homeworks/subscribers","subscription_url":"https://api.github.com/repos/svloyso/java_homeworks/subscription","commits_url":"https://api.github.com/repos/svloyso/java_homeworks/commits{/sha}","git_commits_url":"https://api.github.com/repos/svloyso/java_homeworks/git/commits{/sha}","comments_url":"https://api.github.com/repos/svloyso/java_homeworks/comments{/number}","issue_comment_url":"https://api.github.com/repos/svloyso/java_homeworks/issues/comments{/number}","contents_url":"https://api.github.com/repos/svloyso/java_homeworks/contents/{+path}","compare_url":"https://api.github.com/repos/svloyso/java_homeworks/compare/{base}...{head}","merges_url":"https://api.github.com/repos/svloyso/java_homeworks/merges","archive_url":"https://api.github.com/repos/svloyso/java_homeworks/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/svloyso/java_homeworks/downloads","issues_url":"https://api.github.com/repos/svloyso/java_homeworks/issues{/number}","pulls_url":"https://api.github.com/repos/svloyso/java_homeworks/pulls{/number}","milestones_url":"https://api.github.com/repos/svloyso/java_homeworks/milestones{/number}","notifications_url":"https://api.github.com/repos/svloyso/java_homeworks/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/svloyso/java_homeworks/labels{/name}","releases_url":"https://api.github.com/repos/svloyso/java_homeworks/releases{/id}","deployments_url":"https://api.github.com/repos/svloyso/java_homeworks/deployments","created_at":"2016-03-05T12:13:04Z","updated_at":"2016-03-05T12:13:04Z","pushed_at":"2016-03-05T12:17:33Z","git_url":"git://github.com/svloyso/java_homeworks.git","ssh_url":"git@github.com:svloyso/java_homeworks.git","clone_url":"https://github.com/svloyso/java_homeworks.git","svn_url":"https://github.com/svloyso/java_homeworks","homepage":null,"size":1,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/svloyso/java_homeworks/pulls/1"},"html":{"href":"https://github.com/svloyso/java_homeworks/pull/1"},"issue":{"href":"https://api.github.com/repos/svloyso/java_homeworks/issues/1"},"comments":{"href":"https://api.github.com/repos/svloyso/java_homeworks/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/svloyso/java_homeworks/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/svloyso/java_homeworks/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/svloyso/java_homeworks/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/svloyso/java_homeworks/statuses/16444671db25bff85955e94f22c35724edc717ec"}}}}