{"action":"created","comment":{"url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/pulls/comments/55924495","id":55924495,"diff_hunk":"@@ -0,0 +1,108 @@\n+package kurbanov.trie;\n+\n+import java.util.HashMap;\n+import java.util.Map;\n+\n+public class SimpleTrie implements Trie {\n+\n+    public SimpleTrie() {\n+        children = new HashMap<>();\n+        isEndOfStr = false;\n+        startsWith = 0;\n+        size = 0;\n+    }\n+\n+    @Override\n+    public boolean add(String element) {\n+        if (contains(element))\n+            return false;\n+        if (element.isEmpty()) {\n+            if (!isEndOfStr) {\n+                isEndOfStr = true;\n+                startsWith++;\n+            }\n+        } else {\n+            char letter = element.charAt(0);\n+            String tail = element.substring(1);\n+            SimpleTrie newNode = children.getOrDefault(letter, new SimpleTrie());\n+            if (newNode.add(tail))\n+                startsWith++;\n+            children.put(letter, newNode);\n+        }\n+        size++;\n+        return true;\n+    }\n+\n+    @Override\n+    public boolean contains(String element) {\n+        if (element.isEmpty()) {\n+            return isEndOfStr;\n+        }\n+        char letter = element.charAt(0);\n+        String tail = element.substring(1);\n+        return children.containsKey(letter) && children.get(letter).contains(tail);\n+    }\n+\n+    @Override\n+    public boolean remove(String element) {\n+        if (!contains(element))\n+            return false;\n+\n+        if (element.isEmpty()) {\n+            isEndOfStr = false;\n+        } else {\n+            char letter = element.charAt(0);\n+            String tail = element.substring(1);\n+            SimpleTrie toDel = children.get(letter);\n+            if (toDel.startsWith == 1) {\n+                children.remove(letter);\n+            } else {\n+                toDel.remove(tail);\n+            }\n+        }\n+        startsWith--;\n+        size--;\n+        return true;\n+    }\n+\n+    @Override\n+    public int size() {\n+        return size;\n+    }\n+\n+    @Override\n+    public int howManyStartsWithPrefix(String prefix) {\n+        if (prefix.isEmpty()) {\n+            return startsWith;\n+        }\n+        char letter = prefix.charAt(0);\n+        String tail = prefix.substring(1);\n+        if (children.containsKey(letter)) {\n+            return children.get(letter).howManyStartsWithPrefix(tail);\n+        }\n+        return 0;\n+    }\n+\n+    public String trace(int nSpaces) {\n+        String res = \"\";\n+        for (Map.Entry<Character, SimpleTrie> entry : children.entrySet())\n+        {\n+            for (int i = 0; i < nSpaces; i++) {\n+                res += \"  \";\n+            }\n+            res += entry.getKey().toString();\n+            if (entry.getValue().isEndOfStr) {\n+                res += \"<>\";\n+            } else {\n+                res += \"  \";\n+            }\n+            res += \"\\n\" + entry.getValue().trace(nSpaces + 2);\n+        }\n+        return res;\n+    }\n+\n+    private int startsWith;\n+    private int size;\n+    private boolean isEndOfStr;\n+    private Map<Character, SimpleTrie> children;","path":"Trie/src/kurbanov/trie/SimpleTrie.java","position":107,"original_position":107,"commit_id":"429d3359e892950f7fa3472c28b5079f247e9227","original_commit_id":"429d3359e892950f7fa3472c28b5079f247e9227","user":{"login":"Rauf-Kurbanov","id":1387585,"avatar_url":"https://avatars.githubusercontent.com/u/1387585?v=3","gravatar_id":"","url":"https://api.github.com/users/Rauf-Kurbanov","html_url":"https://github.com/Rauf-Kurbanov","followers_url":"https://api.github.com/users/Rauf-Kurbanov/followers","following_url":"https://api.github.com/users/Rauf-Kurbanov/following{/other_user}","gists_url":"https://api.github.com/users/Rauf-Kurbanov/gists{/gist_id}","starred_url":"https://api.github.com/users/Rauf-Kurbanov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rauf-Kurbanov/subscriptions","organizations_url":"https://api.github.com/users/Rauf-Kurbanov/orgs","repos_url":"https://api.github.com/users/Rauf-Kurbanov/repos","events_url":"https://api.github.com/users/Rauf-Kurbanov/events{/privacy}","received_events_url":"https://api.github.com/users/Rauf-Kurbanov/received_events","type":"User","site_admin":false},"body":"++","created_at":"2016-03-12T17:23:41Z","updated_at":"2016-03-12T17:23:41Z","html_url":"https://github.com/Rauf-Kurbanov/AU-java-course/pull/1#discussion_r55924495","pull_request_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/pulls/comments/55924495"},"html":{"href":"https://github.com/Rauf-Kurbanov/AU-java-course/pull/1#discussion_r55924495"},"pull_request":{"href":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/pulls/1","id":60159686,"html_url":"https://github.com/Rauf-Kurbanov/AU-java-course/pull/1","diff_url":"https://github.com/Rauf-Kurbanov/AU-java-course/pull/1.diff","patch_url":"https://github.com/Rauf-Kurbanov/AU-java-course/pull/1.patch","issue_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/issues/1","number":1,"state":"open","locked":false,"title":" Java05. ДЗ 01, Курбанов Рауф","user":{"login":"Rauf-Kurbanov","id":1387585,"avatar_url":"https://avatars.githubusercontent.com/u/1387585?v=3","gravatar_id":"","url":"https://api.github.com/users/Rauf-Kurbanov","html_url":"https://github.com/Rauf-Kurbanov","followers_url":"https://api.github.com/users/Rauf-Kurbanov/followers","following_url":"https://api.github.com/users/Rauf-Kurbanov/following{/other_user}","gists_url":"https://api.github.com/users/Rauf-Kurbanov/gists{/gist_id}","starred_url":"https://api.github.com/users/Rauf-Kurbanov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rauf-Kurbanov/subscriptions","organizations_url":"https://api.github.com/users/Rauf-Kurbanov/orgs","repos_url":"https://api.github.com/users/Rauf-Kurbanov/repos","events_url":"https://api.github.com/users/Rauf-Kurbanov/events{/privacy}","received_events_url":"https://api.github.com/users/Rauf-Kurbanov/received_events","type":"User","site_admin":false},"body":"@sproshev","created_at":"2016-02-22T11:32:06Z","updated_at":"2016-03-12T17:23:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"76f05f732374159f5d286176b9b01507441ee7bb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/pulls/1/commits","review_comments_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/pulls/1/comments","review_comment_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/issues/1/comments","statuses_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/statuses/429d3359e892950f7fa3472c28b5079f247e9227","head":{"label":"Rauf-Kurbanov:ha_1","ref":"ha_1","sha":"429d3359e892950f7fa3472c28b5079f247e9227","user":{"login":"Rauf-Kurbanov","id":1387585,"avatar_url":"https://avatars.githubusercontent.com/u/1387585?v=3","gravatar_id":"","url":"https://api.github.com/users/Rauf-Kurbanov","html_url":"https://github.com/Rauf-Kurbanov","followers_url":"https://api.github.com/users/Rauf-Kurbanov/followers","following_url":"https://api.github.com/users/Rauf-Kurbanov/following{/other_user}","gists_url":"https://api.github.com/users/Rauf-Kurbanov/gists{/gist_id}","starred_url":"https://api.github.com/users/Rauf-Kurbanov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rauf-Kurbanov/subscriptions","organizations_url":"https://api.github.com/users/Rauf-Kurbanov/orgs","repos_url":"https://api.github.com/users/Rauf-Kurbanov/repos","events_url":"https://api.github.com/users/Rauf-Kurbanov/events{/privacy}","received_events_url":"https://api.github.com/users/Rauf-Kurbanov/received_events","type":"User","site_admin":false},"repo":{"id":52267096,"name":"AU-java-course","full_name":"Rauf-Kurbanov/AU-java-course","owner":{"login":"Rauf-Kurbanov","id":1387585,"avatar_url":"https://avatars.githubusercontent.com/u/1387585?v=3","gravatar_id":"","url":"https://api.github.com/users/Rauf-Kurbanov","html_url":"https://github.com/Rauf-Kurbanov","followers_url":"https://api.github.com/users/Rauf-Kurbanov/followers","following_url":"https://api.github.com/users/Rauf-Kurbanov/following{/other_user}","gists_url":"https://api.github.com/users/Rauf-Kurbanov/gists{/gist_id}","starred_url":"https://api.github.com/users/Rauf-Kurbanov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rauf-Kurbanov/subscriptions","organizations_url":"https://api.github.com/users/Rauf-Kurbanov/orgs","repos_url":"https://api.github.com/users/Rauf-Kurbanov/repos","events_url":"https://api.github.com/users/Rauf-Kurbanov/events{/privacy}","received_events_url":"https://api.github.com/users/Rauf-Kurbanov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Rauf-Kurbanov/AU-java-course","description":"java home assignments","fork":false,"url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course","forks_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/forks","keys_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/teams","hooks_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/hooks","issue_events_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/issues/events{/number}","events_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/events","assignees_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/assignees{/user}","branches_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/branches{/branch}","tags_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/tags","blobs_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/git/refs{/sha}","trees_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/statuses/{sha}","languages_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/languages","stargazers_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/stargazers","contributors_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/contributors","subscribers_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/subscribers","subscription_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/subscription","commits_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/commits{/sha}","git_commits_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/git/commits{/sha}","comments_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/comments{/number}","issue_comment_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/issues/comments{/number}","contents_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/contents/{+path}","compare_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/merges","archive_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/downloads","issues_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/issues{/number}","pulls_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/pulls{/number}","milestones_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/milestones{/number}","notifications_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/labels{/name}","releases_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/releases{/id}","deployments_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/deployments","created_at":"2016-02-22T10:53:25Z","updated_at":"2016-02-22T10:53:25Z","pushed_at":"2016-02-22T11:32:06Z","git_url":"git://github.com/Rauf-Kurbanov/AU-java-course.git","ssh_url":"git@github.com:Rauf-Kurbanov/AU-java-course.git","clone_url":"https://github.com/Rauf-Kurbanov/AU-java-course.git","svn_url":"https://github.com/Rauf-Kurbanov/AU-java-course","homepage":null,"size":2,"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":"Rauf-Kurbanov:master","ref":"master","sha":"750f79594daffa0c527cb198c72286bd30398ff9","user":{"login":"Rauf-Kurbanov","id":1387585,"avatar_url":"https://avatars.githubusercontent.com/u/1387585?v=3","gravatar_id":"","url":"https://api.github.com/users/Rauf-Kurbanov","html_url":"https://github.com/Rauf-Kurbanov","followers_url":"https://api.github.com/users/Rauf-Kurbanov/followers","following_url":"https://api.github.com/users/Rauf-Kurbanov/following{/other_user}","gists_url":"https://api.github.com/users/Rauf-Kurbanov/gists{/gist_id}","starred_url":"https://api.github.com/users/Rauf-Kurbanov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rauf-Kurbanov/subscriptions","organizations_url":"https://api.github.com/users/Rauf-Kurbanov/orgs","repos_url":"https://api.github.com/users/Rauf-Kurbanov/repos","events_url":"https://api.github.com/users/Rauf-Kurbanov/events{/privacy}","received_events_url":"https://api.github.com/users/Rauf-Kurbanov/received_events","type":"User","site_admin":false},"repo":{"id":52267096,"name":"AU-java-course","full_name":"Rauf-Kurbanov/AU-java-course","owner":{"login":"Rauf-Kurbanov","id":1387585,"avatar_url":"https://avatars.githubusercontent.com/u/1387585?v=3","gravatar_id":"","url":"https://api.github.com/users/Rauf-Kurbanov","html_url":"https://github.com/Rauf-Kurbanov","followers_url":"https://api.github.com/users/Rauf-Kurbanov/followers","following_url":"https://api.github.com/users/Rauf-Kurbanov/following{/other_user}","gists_url":"https://api.github.com/users/Rauf-Kurbanov/gists{/gist_id}","starred_url":"https://api.github.com/users/Rauf-Kurbanov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rauf-Kurbanov/subscriptions","organizations_url":"https://api.github.com/users/Rauf-Kurbanov/orgs","repos_url":"https://api.github.com/users/Rauf-Kurbanov/repos","events_url":"https://api.github.com/users/Rauf-Kurbanov/events{/privacy}","received_events_url":"https://api.github.com/users/Rauf-Kurbanov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Rauf-Kurbanov/AU-java-course","description":"java home assignments","fork":false,"url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course","forks_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/forks","keys_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/teams","hooks_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/hooks","issue_events_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/issues/events{/number}","events_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/events","assignees_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/assignees{/user}","branches_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/branches{/branch}","tags_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/tags","blobs_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/git/refs{/sha}","trees_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/statuses/{sha}","languages_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/languages","stargazers_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/stargazers","contributors_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/contributors","subscribers_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/subscribers","subscription_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/subscription","commits_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/commits{/sha}","git_commits_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/git/commits{/sha}","comments_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/comments{/number}","issue_comment_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/issues/comments{/number}","contents_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/contents/{+path}","compare_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/merges","archive_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/downloads","issues_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/issues{/number}","pulls_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/pulls{/number}","milestones_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/milestones{/number}","notifications_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/labels{/name}","releases_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/releases{/id}","deployments_url":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/deployments","created_at":"2016-02-22T10:53:25Z","updated_at":"2016-02-22T10:53:25Z","pushed_at":"2016-02-22T11:32:06Z","git_url":"git://github.com/Rauf-Kurbanov/AU-java-course.git","ssh_url":"git@github.com:Rauf-Kurbanov/AU-java-course.git","clone_url":"https://github.com/Rauf-Kurbanov/AU-java-course.git","svn_url":"https://github.com/Rauf-Kurbanov/AU-java-course","homepage":null,"size":2,"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/Rauf-Kurbanov/AU-java-course/pulls/1"},"html":{"href":"https://github.com/Rauf-Kurbanov/AU-java-course/pull/1"},"issue":{"href":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/issues/1"},"comments":{"href":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/Rauf-Kurbanov/AU-java-course/statuses/429d3359e892950f7fa3472c28b5079f247e9227"}}}}