{"action":"created","comment":{"url":"https://api.github.com/repos/linagora/james-project/pulls/comments/57463217","id":57463217,"diff_hunk":"@@ -19,38 +19,75 @@\n package org.apache.james.jmap.model.mailbox;\n \n import java.util.Locale;\n+import java.util.Map;\n import java.util.Optional;\n+import java.util.function.Function;\n+import java.util.stream.Collectors;\n \n import com.fasterxml.jackson.annotation.JsonValue;\n+import com.google.common.annotations.VisibleForTesting;\n+import com.google.common.base.Objects;\n+import com.google.common.collect.ImmutableList;\n \n-public enum Role {\n-\n-    INBOX(\"inbox\"),\n-    ARCHIVE(\"archive\"),\n-    DRAFTS(\"drafts\"),\n-    OUTBOX(\"outbox\"),\n-    SENT(\"sent\"),\n-    TRASH(\"trash\"),\n-    SPAM(\"spam\"),\n-    TEMPLATES(\"templates\");\n+public class Role {\n \n+    public static final Role INBOX = new Role(\"inbox\");\n+    public static final Role ARCHIVE = new Role(\"archive\");\n+    public static final Role DRAFTS = new Role(\"drafts\");\n+    public static final Role OUTBOX = new Role(\"outbox\");\n+    public static final Role SENT = new Role(\"sent\");\n+    public static final Role TRASH = new Role(\"trash\");\n+    public static final Role SPAM = new Role(\"spam\");\n+    public static final Role TEMPLATES = new Role(\"templates\");\n+    \n+    private static final Map<String, Role> ROLES = \n+            ImmutableList.<Role>of(INBOX, ARCHIVE, DRAFTS, OUTBOX, SENT, TRASH, SPAM, TEMPLATES)\n+            .stream()\n+            .collect(Collectors.toMap((Role x) -> x.name.toLowerCase(Locale.ENGLISH), Function.identity()));\n+    \n     private final String name;\n \n-    Role(String name) {\n+    @VisibleForTesting Role(String name) {\n         this.name = name;\n     }\n \n     public static Optional<Role> from(String name) {\n-        for (Role role : values()) {\n-            if (role.serialize().equals(name.toLowerCase(Locale.ENGLISH))) {\n-                return Optional.of(role);\n-            }\n+        Optional<Role> predefinedRole = Optional.ofNullable(ROLES.get(name.toLowerCase(Locale.ENGLISH)));\n+        if (predefinedRole.isPresent()) {\n+            return predefinedRole;\n+        } else {\n+            return tryBuildCustomRole(name);\n         }\n-        return Optional.empty();\n     }\n \n+    private static Optional<Role> tryBuildCustomRole(String name) {\n+        if (name.startsWith(\"x-\")) {","path":"server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Role.java","position":62,"original_position":62,"commit_id":"64275f731b6413add9fca3a4bdf83fbc4048a6fa","original_commit_id":"fff7de1ed2f10aa2515acf5e576fd176c419b9d7","user":{"login":"rouazana","id":1398581,"avatar_url":"https://avatars.githubusercontent.com/u/1398581?v=3","gravatar_id":"","url":"https://api.github.com/users/rouazana","html_url":"https://github.com/rouazana","followers_url":"https://api.github.com/users/rouazana/followers","following_url":"https://api.github.com/users/rouazana/following{/other_user}","gists_url":"https://api.github.com/users/rouazana/gists{/gist_id}","starred_url":"https://api.github.com/users/rouazana/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rouazana/subscriptions","organizations_url":"https://api.github.com/users/rouazana/orgs","repos_url":"https://api.github.com/users/rouazana/repos","events_url":"https://api.github.com/users/rouazana/events{/privacy}","received_events_url":"https://api.github.com/users/rouazana/received_events","type":"User","site_admin":false},"body":"please extract to public constant","created_at":"2016-03-25T16:55:50Z","updated_at":"2016-03-25T16:55:50Z","html_url":"https://github.com/linagora/james-project/pull/195#discussion_r57463217","pull_request_url":"https://api.github.com/repos/linagora/james-project/pulls/195","_links":{"self":{"href":"https://api.github.com/repos/linagora/james-project/pulls/comments/57463217"},"html":{"href":"https://github.com/linagora/james-project/pull/195#discussion_r57463217"},"pull_request":{"href":"https://api.github.com/repos/linagora/james-project/pulls/195"}}},"pull_request":{"url":"https://api.github.com/repos/linagora/james-project/pulls/195","id":64044284,"html_url":"https://github.com/linagora/james-project/pull/195","diff_url":"https://github.com/linagora/james-project/pull/195.diff","patch_url":"https://github.com/linagora/james-project/pull/195.patch","issue_url":"https://api.github.com/repos/linagora/james-project/issues/195","number":195,"state":"open","locked":false,"title":"James 1710 : SetMailboxesMethod implementation","user":{"login":"mbaechler","id":708318,"avatar_url":"https://avatars.githubusercontent.com/u/708318?v=3","gravatar_id":"","url":"https://api.github.com/users/mbaechler","html_url":"https://github.com/mbaechler","followers_url":"https://api.github.com/users/mbaechler/followers","following_url":"https://api.github.com/users/mbaechler/following{/other_user}","gists_url":"https://api.github.com/users/mbaechler/gists{/gist_id}","starred_url":"https://api.github.com/users/mbaechler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbaechler/subscriptions","organizations_url":"https://api.github.com/users/mbaechler/orgs","repos_url":"https://api.github.com/users/mbaechler/repos","events_url":"https://api.github.com/users/mbaechler/events{/privacy}","received_events_url":"https://api.github.com/users/mbaechler/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-03-24T14:48:00Z","updated_at":"2016-03-25T16:55:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8874b26ec3263066b81e6309a36c4bba9a0559bd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/linagora/james-project/pulls/195/commits","review_comments_url":"https://api.github.com/repos/linagora/james-project/pulls/195/comments","review_comment_url":"https://api.github.com/repos/linagora/james-project/pulls/comments{/number}","comments_url":"https://api.github.com/repos/linagora/james-project/issues/195/comments","statuses_url":"https://api.github.com/repos/linagora/james-project/statuses/64275f731b6413add9fca3a4bdf83fbc4048a6fa","head":{"label":"mbaechler:JAMES-1710","ref":"JAMES-1710","sha":"64275f731b6413add9fca3a4bdf83fbc4048a6fa","user":{"login":"mbaechler","id":708318,"avatar_url":"https://avatars.githubusercontent.com/u/708318?v=3","gravatar_id":"","url":"https://api.github.com/users/mbaechler","html_url":"https://github.com/mbaechler","followers_url":"https://api.github.com/users/mbaechler/followers","following_url":"https://api.github.com/users/mbaechler/following{/other_user}","gists_url":"https://api.github.com/users/mbaechler/gists{/gist_id}","starred_url":"https://api.github.com/users/mbaechler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbaechler/subscriptions","organizations_url":"https://api.github.com/users/mbaechler/orgs","repos_url":"https://api.github.com/users/mbaechler/repos","events_url":"https://api.github.com/users/mbaechler/events{/privacy}","received_events_url":"https://api.github.com/users/mbaechler/received_events","type":"User","site_admin":false},"repo":{"id":39567902,"name":"james-project","full_name":"mbaechler/james-project","owner":{"login":"mbaechler","id":708318,"avatar_url":"https://avatars.githubusercontent.com/u/708318?v=3","gravatar_id":"","url":"https://api.github.com/users/mbaechler","html_url":"https://github.com/mbaechler","followers_url":"https://api.github.com/users/mbaechler/followers","following_url":"https://api.github.com/users/mbaechler/following{/other_user}","gists_url":"https://api.github.com/users/mbaechler/gists{/gist_id}","starred_url":"https://api.github.com/users/mbaechler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbaechler/subscriptions","organizations_url":"https://api.github.com/users/mbaechler/orgs","repos_url":"https://api.github.com/users/mbaechler/repos","events_url":"https://api.github.com/users/mbaechler/events{/privacy}","received_events_url":"https://api.github.com/users/mbaechler/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mbaechler/james-project","description":"Mirror of Apache James Project","fork":true,"url":"https://api.github.com/repos/mbaechler/james-project","forks_url":"https://api.github.com/repos/mbaechler/james-project/forks","keys_url":"https://api.github.com/repos/mbaechler/james-project/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mbaechler/james-project/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mbaechler/james-project/teams","hooks_url":"https://api.github.com/repos/mbaechler/james-project/hooks","issue_events_url":"https://api.github.com/repos/mbaechler/james-project/issues/events{/number}","events_url":"https://api.github.com/repos/mbaechler/james-project/events","assignees_url":"https://api.github.com/repos/mbaechler/james-project/assignees{/user}","branches_url":"https://api.github.com/repos/mbaechler/james-project/branches{/branch}","tags_url":"https://api.github.com/repos/mbaechler/james-project/tags","blobs_url":"https://api.github.com/repos/mbaechler/james-project/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mbaechler/james-project/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mbaechler/james-project/git/refs{/sha}","trees_url":"https://api.github.com/repos/mbaechler/james-project/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mbaechler/james-project/statuses/{sha}","languages_url":"https://api.github.com/repos/mbaechler/james-project/languages","stargazers_url":"https://api.github.com/repos/mbaechler/james-project/stargazers","contributors_url":"https://api.github.com/repos/mbaechler/james-project/contributors","subscribers_url":"https://api.github.com/repos/mbaechler/james-project/subscribers","subscription_url":"https://api.github.com/repos/mbaechler/james-project/subscription","commits_url":"https://api.github.com/repos/mbaechler/james-project/commits{/sha}","git_commits_url":"https://api.github.com/repos/mbaechler/james-project/git/commits{/sha}","comments_url":"https://api.github.com/repos/mbaechler/james-project/comments{/number}","issue_comment_url":"https://api.github.com/repos/mbaechler/james-project/issues/comments{/number}","contents_url":"https://api.github.com/repos/mbaechler/james-project/contents/{+path}","compare_url":"https://api.github.com/repos/mbaechler/james-project/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mbaechler/james-project/merges","archive_url":"https://api.github.com/repos/mbaechler/james-project/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mbaechler/james-project/downloads","issues_url":"https://api.github.com/repos/mbaechler/james-project/issues{/number}","pulls_url":"https://api.github.com/repos/mbaechler/james-project/pulls{/number}","milestones_url":"https://api.github.com/repos/mbaechler/james-project/milestones{/number}","notifications_url":"https://api.github.com/repos/mbaechler/james-project/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mbaechler/james-project/labels{/name}","releases_url":"https://api.github.com/repos/mbaechler/james-project/releases{/id}","deployments_url":"https://api.github.com/repos/mbaechler/james-project/deployments","created_at":"2015-07-23T13:06:08Z","updated_at":"2016-01-28T11:06:21Z","pushed_at":"2016-03-25T16:36:25Z","git_url":"git://github.com/mbaechler/james-project.git","ssh_url":"git@github.com:mbaechler/james-project.git","clone_url":"https://github.com/mbaechler/james-project.git","svn_url":"https://github.com/mbaechler/james-project","homepage":null,"size":11266,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":1,"default_branch":"trunk"}},"base":{"label":"linagora:master","ref":"master","sha":"4e92aefccb24badcb187e30d1cf35cf392e50942","user":{"login":"linagora","id":1230365,"avatar_url":"https://avatars.githubusercontent.com/u/1230365?v=3","gravatar_id":"","url":"https://api.github.com/users/linagora","html_url":"https://github.com/linagora","followers_url":"https://api.github.com/users/linagora/followers","following_url":"https://api.github.com/users/linagora/following{/other_user}","gists_url":"https://api.github.com/users/linagora/gists{/gist_id}","starred_url":"https://api.github.com/users/linagora/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/linagora/subscriptions","organizations_url":"https://api.github.com/users/linagora/orgs","repos_url":"https://api.github.com/users/linagora/repos","events_url":"https://api.github.com/users/linagora/events{/privacy}","received_events_url":"https://api.github.com/users/linagora/received_events","type":"Organization","site_admin":false},"repo":{"id":39182136,"name":"james-project","full_name":"linagora/james-project","owner":{"login":"linagora","id":1230365,"avatar_url":"https://avatars.githubusercontent.com/u/1230365?v=3","gravatar_id":"","url":"https://api.github.com/users/linagora","html_url":"https://github.com/linagora","followers_url":"https://api.github.com/users/linagora/followers","following_url":"https://api.github.com/users/linagora/following{/other_user}","gists_url":"https://api.github.com/users/linagora/gists{/gist_id}","starred_url":"https://api.github.com/users/linagora/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/linagora/subscriptions","organizations_url":"https://api.github.com/users/linagora/orgs","repos_url":"https://api.github.com/users/linagora/repos","events_url":"https://api.github.com/users/linagora/events{/privacy}","received_events_url":"https://api.github.com/users/linagora/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/linagora/james-project","description":"Mirror of Apache James Project","fork":true,"url":"https://api.github.com/repos/linagora/james-project","forks_url":"https://api.github.com/repos/linagora/james-project/forks","keys_url":"https://api.github.com/repos/linagora/james-project/keys{/key_id}","collaborators_url":"https://api.github.com/repos/linagora/james-project/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/linagora/james-project/teams","hooks_url":"https://api.github.com/repos/linagora/james-project/hooks","issue_events_url":"https://api.github.com/repos/linagora/james-project/issues/events{/number}","events_url":"https://api.github.com/repos/linagora/james-project/events","assignees_url":"https://api.github.com/repos/linagora/james-project/assignees{/user}","branches_url":"https://api.github.com/repos/linagora/james-project/branches{/branch}","tags_url":"https://api.github.com/repos/linagora/james-project/tags","blobs_url":"https://api.github.com/repos/linagora/james-project/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/linagora/james-project/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/linagora/james-project/git/refs{/sha}","trees_url":"https://api.github.com/repos/linagora/james-project/git/trees{/sha}","statuses_url":"https://api.github.com/repos/linagora/james-project/statuses/{sha}","languages_url":"https://api.github.com/repos/linagora/james-project/languages","stargazers_url":"https://api.github.com/repos/linagora/james-project/stargazers","contributors_url":"https://api.github.com/repos/linagora/james-project/contributors","subscribers_url":"https://api.github.com/repos/linagora/james-project/subscribers","subscription_url":"https://api.github.com/repos/linagora/james-project/subscription","commits_url":"https://api.github.com/repos/linagora/james-project/commits{/sha}","git_commits_url":"https://api.github.com/repos/linagora/james-project/git/commits{/sha}","comments_url":"https://api.github.com/repos/linagora/james-project/comments{/number}","issue_comment_url":"https://api.github.com/repos/linagora/james-project/issues/comments{/number}","contents_url":"https://api.github.com/repos/linagora/james-project/contents/{+path}","compare_url":"https://api.github.com/repos/linagora/james-project/compare/{base}...{head}","merges_url":"https://api.github.com/repos/linagora/james-project/merges","archive_url":"https://api.github.com/repos/linagora/james-project/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/linagora/james-project/downloads","issues_url":"https://api.github.com/repos/linagora/james-project/issues{/number}","pulls_url":"https://api.github.com/repos/linagora/james-project/pulls{/number}","milestones_url":"https://api.github.com/repos/linagora/james-project/milestones{/number}","notifications_url":"https://api.github.com/repos/linagora/james-project/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/linagora/james-project/labels{/name}","releases_url":"https://api.github.com/repos/linagora/james-project/releases{/id}","deployments_url":"https://api.github.com/repos/linagora/james-project/deployments","created_at":"2015-07-16T07:04:59Z","updated_at":"2016-03-17T09:08:41Z","pushed_at":"2016-03-25T16:36:25Z","git_url":"git://github.com/linagora/james-project.git","ssh_url":"git@github.com:linagora/james-project.git","clone_url":"https://github.com/linagora/james-project.git","svn_url":"https://github.com/linagora/james-project","homepage":null,"size":12461,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":11,"forks":6,"open_issues":11,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/linagora/james-project/pulls/195"},"html":{"href":"https://github.com/linagora/james-project/pull/195"},"issue":{"href":"https://api.github.com/repos/linagora/james-project/issues/195"},"comments":{"href":"https://api.github.com/repos/linagora/james-project/issues/195/comments"},"review_comments":{"href":"https://api.github.com/repos/linagora/james-project/pulls/195/comments"},"review_comment":{"href":"https://api.github.com/repos/linagora/james-project/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/linagora/james-project/pulls/195/commits"},"statuses":{"href":"https://api.github.com/repos/linagora/james-project/statuses/64275f731b6413add9fca3a4bdf83fbc4048a6fa"}}}}